Make list tests actually test lists
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@oracle.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
d0da0e9c3b
commit
8f8dcfee20
24
test/list.c
24
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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user