Menu

FALSE NEGATIVE: `zerodiv` misses a scalar zeroed by `memset`

Rodri
2 days ago
1 day ago
  • Rodri

    Rodri - 2 days ago

    Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when memset zeroes a local integer before it is used as a divisor.

    Affected tool

    Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev

    Affected checker

    Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond)

    Minimal reproducer

    #include <cstring>
    
    int test() {
      int value = 1;
      std::memset(&value, 0, sizeof(value));
      return 1 / value;
    }
    

    Reproduction command

    cppcheck --version
    cppcheck --enable=warning --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-memset.cpp
    

    Current behavior

    Cppcheck produces neither a zerodiv nor a zerodivcond diagnostic. The checker report lists CheckOther::checkZeroDivision as active.

    Expected behavior

    Cppcheck should report line 6 because memset sets every byte of the local integer to zero.

     
  • CHR

    CHR - 1 day ago
     

Log in to post a comment.