Menu

--supress=unmatchedSupression not hiding --supress rule with a wildcard in filename

2019-12-06
2019-12-10
  • Lionel Gimbert

    Lionel Gimbert - 2019-12-06

    Hello,

    The--suppress=unmatchedSuppression does not seem to work for the suppression with wildcard in the filename part.

    If we have the following sources:
    1. includeFaultyHeader.cpp => just containing #include "include/FaultyHeader.h
    2. IncludeNothing.cpp => empty
    3. include/FaultyHeader.h => class A{ A(int i){}} (or anything else reporting an error)

    Case that works as I expect:
    1. cppcheck --enable=all includeFaultyHeader.cpp => warning
    2. cppcheck --enable=all IncludeNothing.cpp => no warning
    3. cppcheck --enable=all --suppress=noExplicitConstructor includeFaultyHeader.cpp => no warning
    4. cppcheck --enable=all --suppress=noExplicitConstructor IncludeNothing.cpp => warn for unmatched suppression
    5. cppcheck --enable=all --suppress=noExplicitConstructor --suppress=unmatchedSuppression includeFaultyHeader.cpp => no warning
    6. cppcheck --enable=all --suppress=noExplicitConstructor --suppress=unmatchedSuppression IncludeNothing.cpp => no warning
    7. cppcheck --enable=all --suppress=*:include/FaultyHeader.h --suppress=unmatchedSuppression includeFaultyHeader.cpp => no warning
    8. cppcheck --enable=all --suppress=*:include/FaultyHeader.h --suppress=unmatchedSuppression IncludeNothing.cpp => no warning

    Case that don't work what I except:
    1. cppcheck --enable=all --suppress=*:include/* --suppress=unmatchedSuppression IncludeNothing.cpp => warn for unmatched suppression, expecting no warning
    2. cppcheck --enable=all --suppress=uselessAssignmentArg:include/* --suppress=unmatchedSuppression includeFaultyHeader.cpp => warn for unmatched suppression, expecting no warning

    So the issue seams to be due to the wild card in the filename.

    I take a quick look at how cppcheck source code handle the unmatched suppression but havn't figured anything obvious.

     

    Last edit: Lionel Gimbert 2019-12-06
  • versat

    versat - 2019-12-09

    I have reproduced it (thanks for the detailed report, it was no problem) and I found something.
    The interesting place is here: https://github.com/danmar/cppcheck/blob/0507b1a2b62eb095871606adfcafa9c210aaa971/lib/errorlogger.cpp#L565
    Debugging through this loop shows that this should work (note the :* after unmatchedSuppression):

    cppcheck --enable=all --suppress=*:include/* --suppress=unmatchedSuppression:* IncludeNothing.cpp
    

    while this does not work (as you wrote):

    cppcheck --enable=all --suppress=*:include/* --suppress=unmatchedSuppression IncludeNothing.cpp
    

    The loop only tests for global suppressions where the filename matches or where filename is set to *. Maybe an empty filename should be handled the same as a *. IMHO that would make sense, if nothing is specified, everything should match I guess.

    Edit: I created a PR that would fix this issue.

     

    Last edit: versat 2019-12-09
    • Lionel Gimbert

      Lionel Gimbert - 2019-12-10

      I have reproduced it (thanks for the detailed report, it was no problem)

      As a dev I know the pain of bug report without clear reproducing step ;)

      Edit: I created a PR that would fix this issue.

      Great news! Thanks

       

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.