[PATCH] Make list tests actually test lists

Peter Hutterer peter.hutterer at who-t.net
Mon Sep 8 01:17:10 PDT 2014


On Thu, Sep 04, 2014 at 11:18:03PM -0700, Alan Coopersmith wrote:
> Coverity scan detected that asserts were setting values, not checking them:
> 
> CID 53252: Side effect in assertion (ASSERT_SIDE_EFFECT)
>   assignment_where_comparison_intended: Assignment item->b = i * 2
>   has a side effect. This code will work differently in a non-debug build.
>   Did you intend to use a comparison ("==") instead?
> 
> CID 53259: Side effect in assertion (ASSERT_SIDE_EFFECT)
>   assignment_where_comparison_intended: Assignment item->a = i
>   has a side effect. This code will work differently in a non-debug build.
>   Did you intend to use a comparison ("==") instead?
> 
> CID 53260: Side effect in assertion (ASSERT_SIDE_EFFECT)
>   assignment_where_comparison_intended: Assignment item->a = i
>   has a side effect. This code will work differently in a non-debug build.
>   Did you intend to use a comparison ("==") instead?
> 
> CID 53261: Side effect in assertion (ASSERT_SIDE_EFFECT)
>   assignment_where_comparison_intended: Assignment item->b = i * 2
>   has a side effect. This code will work differently in a non-debug build.
>   Did you intend to use a comparison ("==") instead?
> 
> Fixing those to be == caused test_nt_list_insert to start failing as
> part assumed append order, part assumed insert order, so it had to be
> fixed to use consistent ordering.
> 
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

quis probat ipsa probaties*

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

Cheers,
   Peter

* -ish. it's been a long time....


> ---
>  test/list.c |   24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/test/list.c b/test/list.c
> index f9f54ee..28d9609 100644
> --- a/test/list.c
> +++ b/test/list.c
> @@ -249,15 +249,15 @@ test_nt_list_append(void)
>  
>      /* Test using nt_list_next */
>      for (item = foo, i = 1; i <= 10; i++, item = nt_list_next(item, next)) {
> -        assert(item->a = i);
> -        assert(item->b = i * 2);
> +        assert(item->a == i);
> +        assert(item->b == i * 2);
>      }
>  
>      /* Test using nt_list_for_each_entry */
>      i = 1;
>      nt_list_for_each_entry(item, foo, next) {
> -        assert(item->a = i);
> -        assert(item->b = i * 2);
> +        assert(item->a == i);
> +        assert(item->b == i * 2);
>          i++;
>      }
>      assert(i == 11);
> @@ -270,11 +270,11 @@ test_nt_list_insert(void)
>      struct foo *foo = calloc(10, sizeof(struct foo));
>      struct foo *item;
>  
> -    foo->a = 10;
> -    foo->b = 20;
> +    foo->a = 1;
> +    foo->b = 2;
>      nt_list_init(foo, next);
>  
> -    for (item = &foo[1], i = 9; i > 0; i--, item++) {
> +    for (item = &foo[1], i = 10; i > 1; i--, item++) {
>          item->a = i;
>          item->b = i * 2;
>          nt_list_init(item, next);
> @@ -282,16 +282,16 @@ test_nt_list_insert(void)
>      }
>  
>      /* Test using nt_list_next */
> -    for (item = foo, i = 10; i > 0; i--, item = nt_list_next(item, next)) {
> -        assert(item->a = i);
> -        assert(item->b = i * 2);
> +    for (item = foo, i = 1; i <= 10; i++, item = nt_list_next(item, next)) {
> +        assert(item->a == i);
> +        assert(item->b == i * 2);
>      }
>  
>      /* Test using nt_list_for_each_entry */
>      i = 1;
>      nt_list_for_each_entry(item, foo, next) {
> -        assert(item->a = i);
> -        assert(item->b = i * 2);
> +        assert(item->a == i);
> +        assert(item->b == i * 2);
>          i++;
>      }
>      assert(i == 11);
> -- 
> 1.7.9.2
> 


More information about the xorg-devel mailing list