Menu

Can you please fix the compiler warnings in CPPCheck source code?

2021-10-11
2021-10-13
  • Steve Albright

    Steve Albright - 2021-10-11

    Treat warnings as errors and do some cleanup?

    I was bringing in 2.6 today and have twice the issues I had in 2.5 so I'm hoping you will do me a favor for all the issues I've submitted and fix at least some of these - which in turn could also turn into things cppcheck could detect (I assume you ran 2.6 against your own source and it didn't complain).

    For various reasons, I'm currently not using your make file with the suppressions (but hope to in the future). When compiling with gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, the older compiler I'm forced to use is flagging valid issues in the CPPCheck source that cause me extra work.

    For instance:

    ../cppcheck/lib/checkcondition.cpp (line #1820, bool result)
    warning: result may be used uninitialized in this function [-Wmaybe-uninitialized]

    .../cppcheck/src/cppcheck/lib/tokenize.cpp (line #4481, const Token * templateToken)
    warning: unused variable templateToken [-Wunused-variable]

    ../cppcheck/src/cppcheck/cli/filelister.cpp (line #224, readdir_r is deprecated)
    warning: int readdir_r(DIR, dirent, dirent) is deprecated [-Wdeprecated-declarations]

    .../cppcheck/src/cppcheck/lib/valueflow.cpp (line #435, case '<<', could easily be done with ifs and strings instead)
    warning: multi-character character constant [-Wmultichar]

    .../cppcheck/src/cppcheck/lib/valueflow.cpp (line #2770, MathLib::bigint intval - can you just set to zero to avoid the warning?)
    warning: intval may be used uninitialized in this function [-Wmaybe-uninitialized]

    .../cppcheck/src/cppcheck/lib/valueflow.cpp (line #6296 unused static function)
    warning: void setTokenValues(Token, const std::cxx11::list<valueflow::value>&, const Settings</valueflow::value>) defined but not used [-Wunused-function]
    **

     
  • Steve Albright

    Steve Albright - 2021-10-12

    Well, I was kind of surprised with all this issues reported after I went ahead and ran CPPCheck 2.6 against its source and it came up with pages of issues. Fixing issues is how I come up with the false positives and I generally try to get down to no unreported issues or very few across a repo.

    The bulk of the issues are missingOverride (191) and useStlAlgorithm (76) but also some ConfigurationNotChecked (8), unmatchedSuppression (4), constVariable (1), knownConditionTrueFalse (1) and shiftTooManyBits (1).

    I have a script to add the missingOverride if you want me to do a pull request to fix those 191 issues.

     
  • CHR

    CHR - 2021-10-12

    Might those missingOverride be due to an undefined macro?

     
    • Steve Albright

      Steve Albright - 2021-10-12

      That could be the case, I opened one at random and see this

      std::string classInfo() const OVERRIDE {

      so if it isn't finding OVERRIDE that could be the problem.

       
      • Daniel Marjamäki

        Please always use -D__CPPCHECK__ when you check cppcheck source code.

        We of course perform a self check in our CI. We have some suppressions in cppcheck/.travis_suppressions but hmm as far as I see that does not say anything about "constVariable (1), knownConditionTrueFalse (1) and shiftTooManyBits (1)."

         
  • Daniel Marjamäki

    Treat warnings as errors and do some cleanup?

    The biggest problem with this is that everybody uses different compilers and compiler versions. I can write code and it looks very good for me. No warnings. I merge my changes. Then you download the code and try to compile it and get various warnings.

    We can have a step in the CI where warnings are treated as errors. Not sure maybe we have it already but if we don't that sounds good to me.

     
  • Steve Albright

    Steve Albright - 2021-10-13

    Thanks, I know what you mean and run into those compiler specific issues when switching between clang and gcc.

     

Log in to post a comment.