Menu

cppcheck 1.84 -> 1.85+: errors no more reported?

GKA
2019-07-19
2019-07-22
  • GKA

    GKA - 2019-07-19

    hi,

    i compared cppcheck 1.84 till 1.88 on the enclosed test source code
    (including cppcheck reports)

    according to my tests, it started to malfunction at version 1.85.

    please check, these are critical errors no more detected on that sample
    (arrayIndexOutOfBounds, memleak, mismatchAllocDealloc)

    thank you

    BR,

    GKA

    NB: please rename the attached file extension "extZ" to "zip", i could
    not pass the "
    Blacklisted file extension detected"

     

    Last edit: GKA 2019-07-19
  • versat

    versat - 2019-07-22

    The problem seems to be that there is at least one syntax error which causes an internal AST error.
    Cppcheck does not further analyze a file when such an error is detected.
    Code that is checked by Cppcheck should be compilable to get useful results.
    main.cpp from the zip file looks like this:

    #include "sub/Sub.h"
    
    void f1()
    {
        char *p;
        *p = 0;
    }
    
    double f2()
    {
        int *i = new[4];
        double d = .;
        return d;
    }
    
    int f3()
    {
        char a[5];
        a[5] = 0;
        return 0;
    }
    
    int main()
    {
        f1();
        double d = f2();
        int i = f3();
        Sub sub = Sub(5);
    }
    

    Output from g++:

    $ g++ -fsyntax-only ./src/main.cpp
    ./src/main.cpp: In function ‘double f2()’:
    ./src/main.cpp:12:17: error: expected type-specifier before ‘[’ token
         int *i = new[4];
                     ^
    ./src/main.cpp:13:16: error: expected primary-expression before ‘.’ token
         double d = .;
                    ^
    ./src/main.cpp:13:17: error: expected unqualified-id before ‘;’ token
         double d = .;
                     ^
    

    Cppcheck 1.89 dev (HEAD) outputs:

    $ ./cppcheck --template=gcc ./src
    Checking src/main.cpp ...
    src/main.cpp:13:16: warning: syntax error: = . ; [syntaxError]
    
                   ^
    1/2 files checked 69% done
    Checking src/sub/Sub.cpp ...
    2/2 files checked 100% done
    
     
  • GKA

    GKA - 2019-07-22

    It's all good now.
    I was not aware that cppcheck won't do any further with syntax errors, I was just throwing some bad code. Thank you for the hint.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.