]> git.ipfire.org Git - thirdparty/bind9.git/commit
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)
commitbe38f0c33a248c12722b7ea3c08ba4032052feb4
tree21f98e969d2e78e324bb0fbf8544bb613000cbbb
parentab4c9116290cdef72f4f80ed9f70e0e6082d2929
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.
lib/dns/tests/rbt_serialize_test.c