Menu

cppcheck ignores an -i lib/file.c option (regression)

2024-09-20
2025-01-19
  • Gwyn Ciesla

    Gwyn Ciesla - 2024-09-20

    From: https://bugzilla.redhat.com/show_bug.cgi?id=2311947

    Description of problem:
    I run cppcheck in a project that contains a file generated by flex which I want cppcheck to ignore. That's why I use the '-i' option. With the new version of cppcheck (2.15.0) issues in the ignored file are reported.

    Version-Release number of selected component (if applicable):
    2.15.0-1.fc40

    How reproducible:
    100% (in the project)

    Steps to Reproduce:
    1. git clone https://github.com/cfengine/core.git
    2. cd core
    3. ./autogen.sh
    4. make
    5. cppcheck --quiet -j4 --error-exitcode=1 ./ --suppressions-list=tests/static-check/cppcheck_suppressions.txt --check-level=exhaustive --include=config.h -I cf-serverd/ -I libpromises/ -I libcfnet/ -I libntech/libutils/ -i 3rdparty -i .github/codeql -i libntech/.lgtm -i tests -i libpromises/cf3lex.c

    Actual results:
    cf3lex.c:2370:2: warning: Possible null pointer dereference: b [nullPointer]

    ^
    cf3lex.c:2263:18: note: Calling function 'yy_init_buffer', 1st argument '(yy_buffer_stack)?(yy_buffer_stack)[yy_buffer_stack_top]:NULL' value is 0

                 ^
    

    cf3lex.c:2370:2: note: Null pointer dereference

    ^
    cf3lex.c:2371:2: warning: Possible null pointer dereference: b [nullPointer]

    ^
    cf3lex.c:2263:18: note: Calling function 'yy_init_buffer', 1st argument '(yy_buffer_stack)?(yy_buffer_stack)[yy_buffer_stack_top]:NULL' value is 0

                 ^
    

    cf3lex.c:2371:2: note: Null pointer dereference

    ^

    Expected results:
    No issues found.

    Additional info:
    This works as expected with both 2.13.0-3.fc40 and 2.14.2-1.fc40. It is a regression in 2.15.0.

    I tried things like './libpromises/cf3lex.c' or just 'cf3lex.c', but with no success. I also tried reproducing the issue in a simpler setup, but there it worked as expected:

    [vpodzime@vp-desktop cppcheck_test]$ cppcheck ./
    Checking strdup_null.c ...
    strdup_null.c:5:5: error: Memory leak: copy [memleak]
    return 0;
    ^
    strdup_null.c:4:25: error: Null pointer dereference [nullPointer]
    char *copy = strdup(NULL);
    ^
    1/2 files checked 18% done
    Checking strtok_test.c ...
    2/2 files checked 100% done
    [vpodzime@vp-desktop cppcheck_test]$ cppcheck ./ -i strdup_null.c
    Checking strtok_test.c ...

     
  • Oliver Stöneberg

    I am able to reproduce it :

    $ cppcheck -D__GNUC__ ./ -j$(nproc) 2>&1 | grep cf3lex.c
    Checking libpromises/cf3lex.c ...
    [...]
    
    $ cppcheck -D__GNUC__ ./ -j$(nproc) -i cf3lex.c 2>&1 | grep cf3lex.c
    
    $ cppcheck -D__GNUC__ ./ -j$(nproc) -i libpromises/cf3lex.c 2>&1 | grep cf3lex.c
    
    cppcheck -D__GNUC__ ./ -j$(nproc) --suppressions-list=tests/static-check/cppcheck_suppressions.txt --include=config.h -I cf-serverd/ -I libpromises/ -I libcfnet/ -I libntech/libutils/ -i 3rdparty -i .github/codeql -i libntech/.lgtm -i tests -i libpromises/cf3lex.c 2>&1 | grep cf3lex.c     
    Checking libpromises/cf3lex.c ...
    [...]
    
    $ cppcheck -D__GNUC__ ./ -j$(nproc) --include=config.h -i tests -i libpromises/cf3lex.c 2>&1 | grep cf3lex.c
    Checking libpromises/cf3lex.c ...
    [...]
    
     
  • Oliver Stöneberg

     

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.