test-resv-mem: Fix CID 1523911
PATCH 1/1 test-resv-mem: Fix CID 1523911
Coverity complains about passing "&expected" to "run_range_inverse_array", which dereferences null "expected". I guess the problem is that the compare_ranges() loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given the g_assert_cmpint() just before the loop. So the code looks safe to me.
Nevertheless adding a test on expected before the loop to get rid of the warning.
---
Hope this fixes the Coverity warning as I cannot test.
--- tests/unit/test-resv-mem.c | 4 ++++ 1 file changed, 4 insertions(+)
tests/unit/test-resv-mem.c +4 -0
@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList *ranges,print_ranges ("out" , ranges);print_ranges ("expected" , expected);#endif +if (!expected) { +g_assert_true (!ranges); +return ; + } g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected));for (l = ranges, e = expected; l ; l = l->next, e = e->next) {Range *r = (Range *)l->data;
Signature · 1 line
2.41.0
Quoted 26 lines · Eric Auger
Coverity complains about passing "&expected" to "
run_range_inverse_array", which dereferences null "expected". I guess the problem is that thecompare_ranges()loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given theg_assert_cmpint()just before the loop. So the code looks safe to me.Nevertheless adding a test on expected before the loop to get rid of the warning.
---
Hope this fixes the Coverity warning as I cannot test.
--- tests/unit/test-resv-mem.c | 4 ++++ 1 file changed, 4 insertions(+)tests/unit/test-resv-mem.c +0
-0
tests/unit/test-resv-mem.c static void compare_ranges(const char *prefix, GList *ranges, · line 53
Quoted 10 lines
tests/unit/test-resv-mem.c +4
-0@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList *ranges,print_ranges ("out" , ranges);print_ranges ("expected" , expected);#endif +if (!expected) { +g_assert_true (!ranges); +return ; + } g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected));for (l = ranges, e = expected; l ; l = l->next, e = e->next) {Range *r = (Range *)l->data;
I'll queue it (unless somebody else wants to take this?).
Quoted 40 lines · Thomas Huth
Quoted 26 lines · Eric Auger
Coverity complains about passing "&expected" to "
run_range_inverse_array", which dereferences null "expected". I guess the problem is that thecompare_ranges()loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given theg_assert_cmpint()just before the loop. So the code looks safe to me.Nevertheless adding a test on expected before the loop to get rid of the warning.
---
Hope this fixes the Coverity warning as I cannot test.
---
tests/unit/test-resv-mem.c| 4 ++++1 file changed, 4 insertions(+)tests/unit/test-resv-mem.c +0
-0tests/unit/test-resv-mem.c static void compare_ranges(const char *prefix, GList *ranges, · line 53
Quoted 10 lines
tests/unit/test-resv-mem.c +4
-0@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList *ranges, print_ranges("out", ranges); print_ranges("expected", expected); #endif + if (!expected) { + g_assert_true(!ranges); + return; + } g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected)); for (l = ranges, e = expected; l ; l = l->next, e = e->next) { Range *r = (Range *)l->data;Reviewed-by Thomas Huth <[email protected]>
Quoted 1 line
I'll queue it (unless somebody else wants to take this?).
There is also another fix for the same series :
https://lore.kernel.org/qemu-devel/[email protected]/
I was waiting to have a little more for VFIO to queue both but they could go through your queue also.
Thanks,
C.
Quoted 44 lines · Cédric Le Goater
Quoted 41 lines · Thomas Huth
Quoted 36 lines · Eric Auger
Coverity complains about passing "&expected" to "
run_range_inverse_array", which dereferences null "expected". I guess the problem is that thecompare_ranges()loop dereferences 'e' without testing it. However the loop condition is based on 'ranges' which is garanteed to have the same length as 'expected' given theg_assert_cmpint()just before the loop. So the code looks safe to me.Nevertheless adding a test on expected before the loop to get rid of the warning.
---
Hope this fixes the Coverity warning as I cannot test.
---
tests/unit/test-resv-mem.c| 4 ++++1 file changed, 4 insertions(+)tests/unit/test-resv-mem.c +4
-0@@ -44,6 +44,10 @@ static void compare_ranges(const char *prefix, GList *ranges, print_ranges("out", ranges); print_ranges("expected", expected); #endif + if (!expected) { + g_assert_true(!ranges); + return; + } g_assert_cmpint(g_list_length(ranges), ==, g_list_length(expected)); for (l = ranges, e = expected; l ; l = l->next, e = e->next) {Quoted 1 line
Range *r = (Range *)l->data;
Reviewed-by Thomas Huth <[email protected]>Quoted 1 line
I'll queue it (unless somebody else wants to take this?).
Quoted 7 lines
There is also another fix for the same series :
https://lore.kernel.org/qemu-devel/[email protected]/
I was waiting to have a little more for VFIO to queue both but they could go through your queue also.
I'm just looking at patches that affect tests/ ... the other fix is not related to that, so I won't pick up that one.
Thomas