From: Michał Kępień Date: Wed, 4 Mar 2020 11:41:01 +0000 (+0100) Subject: Fix cppcheck 1.90 warnings X-Git-Tag: v9.11.17~12^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=be38f0c33a248c12722b7ea3c08ba4032052feb4;p=thirdparty%2Fbind9.git Fix cppcheck 1.90 warnings cppcheck 1.90 reports the following false positives for lib/dns/tests/rbt_serialize_test.c: lib/dns/tests/rbt_serialize_test.c:412:12: warning: Either the condition 'base!=NULL' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck] p = base + (r % filesize); ^ lib/dns/tests/rbt_serialize_test.c:407:20: note: Assuming that condition 'base!=NULL' is not redundant assert_true(base != NULL && base != MAP_FAILED); ^ lib/dns/tests/rbt_serialize_test.c:405:14: note: Assignment 'base=mmap(NULL,filesize,PROT_READ|PROT_WRITE,0|MAP_PRIVATE,fd,0)', assigned value is 0 base = mmap(NULL, filesize, PROT_READ|PROT_WRITE, ^ lib/dns/tests/rbt_serialize_test.c:412:12: note: Null pointer addition p = base + (r % filesize); ^ lib/dns/tests/rbt_serialize_test.c:413:12: warning: Either the condition 'base!=NULL' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck] q = base + filesize; ^ lib/dns/tests/rbt_serialize_test.c:407:20: note: Assuming that condition 'base!=NULL' is not redundant assert_true(base != NULL && base != MAP_FAILED); ^ lib/dns/tests/rbt_serialize_test.c:405:14: note: Assignment 'base=mmap(NULL,filesize,PROT_READ|PROT_WRITE,0|MAP_PRIVATE,fd,0)', assigned value is 0 base = mmap(NULL, filesize, PROT_READ|PROT_WRITE, ^ lib/dns/tests/rbt_serialize_test.c:413:12: note: Null pointer addition q = base + filesize; ^ This is caused by cppcheck not understanding how cmocka's assert_true() macro works. The problem being reported is a false positive: if mmap() fails, the lines flagged by cppcheck will never be reached. Address the problem by suppressing nullPointerArithmeticRedundantCheck warnings for the affected lines. --- diff --git a/lib/dns/tests/rbt_serialize_test.c b/lib/dns/tests/rbt_serialize_test.c index 16aacd14539..3626fc516c8 100644 --- a/lib/dns/tests/rbt_serialize_test.c +++ b/lib/dns/tests/rbt_serialize_test.c @@ -409,7 +409,9 @@ deserialize_corrupt_test(void **state) { /* Randomly fuzz a portion of the memory */ isc_random_get(&r); + /* cppcheck-suppress nullPointerArithmeticRedundantCheck */ p = base + (r % filesize); + /* cppcheck-suppress nullPointerArithmeticRedundantCheck */ q = base + filesize; isc_random_get(&r); q -= (r % (q - p));