]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix cppcheck 1.90 warnings
authorMichał Kępień <michal@isc.org>
Wed, 4 Mar 2020 11:41:01 +0000 (12:41 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 4 Mar 2020 11:41:01 +0000 (12:41 +0100)
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.

lib/dns/tests/rbt_serialize_test.c

index 16aacd1453988636ca9940db929da75ced7dffb7..3626fc516c8cd9e499477d2c09f791d1cfd2e35c 100644 (file)
@@ -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));