Menu

[bug] addons: Line suppressions acts as global suppressions

2024-12-13
2025-01-07
  • David GARCIN

    David GARCIN - 2024-12-13

    Hello,

    I'm trying to create my own python rules following the available addons example.
    I ran into a problem with inline suppressions : If a suppression is set on a specific line, any error occuring in the file is suppressed.

    The problem seems to be the global suppression condition in the Suppression.isMatch method.

    Indeed the line suppression has the same condition as the global suppression, except for the and (self.lineNumber is not None and int(line) == int(self.lineNumber)) part.
    Thus, any file suppression not matching the line is applied by the global suppression mechanism regardless.

    I ended up defining my own version of the cppcheckdata.is_suppressed method, without global suppression support, to work-around this issue.

     

    Last edit: David GARCIN 2024-12-13
  • David GARCIN

    David GARCIN - 2024-12-13

    I created an issue on the tracker : https://trac.cppcheck.net/ticket/13417 (initially forgot my user id ...)

     

    Last edit: David GARCIN 2024-12-13
  • Tommie Skriver

    Tommie Skriver - 2024-12-20

    Hi!
    I did not have time to create a Trac-account to add info there (as requested) - but here is a simplified issue i saw, like this (on Windows 2.16.0 GUI, platform=pic8-enhanced):

    static const int8_t variable __at(0x00100u); // cppcheck: accepted
    static const int8_t arrayA[0x100u] __at(0x01000u); // cppcheck: 'syntaxError'
    - cppcheck bailed out

    So, I tried to suppress the line and had another line after that (expecting the new line to also fail) :

    static const int8_t variable __at(0x00100u); // cppcheck: accepted
    // cppcheck-suppress [syntaxError]
    static const int8_t arrayA[0x100u] __at(0x01000u); // cppcheck: accepted
    static const int8_t arrayB[0x100u] __at(0x01100u); // cppcheck: accepted

    As mentioned, it looks like a line-suppression turns into a global suppression (at least in that file).

    I hope it helps!
    /Regards!

     
    • Oliver Stöneberg

      This is because because syntaxError is a "critical" error which means that the processing is stopped at that point. So you will only suppress the error being shown but that will not enable Cppcheck to proceed the processing - thus you will not get an error on the next line.

      Suppressing "critical" errors is dangerous and should only be done temporally. This probably needs better documentation and/or a message which indicates that (possibly within --check-config which I am currently evaluating for other things).

       
      • Tommie Skriver

        Tommie Skriver - 2025-01-07

        Hi!
        I'm usually not suppressing critical errors - but the above example is an exception :)
        Thanks for the explanation - I wasn't aware about the differences on the error types, but it makes sense!

        But then, as mentioned below, why is the syntaxError even thrown?
        For the static const int8_t type just above, there is no error, although the syntax is the same. Only the type is different: basic data vs. array type.

        Thanks for looking into this!

         
        • CHR

          CHR - 2025-01-07

          __at(...) is a non-standard extension. Passing this to cppcheck should avoid the syntaxError: -D__at(x)=

           
  • Tommie Skriver

    Tommie Skriver - 2024-12-20

    BTW: There might be two bugs hidden in the above - the second is then the 'syntaxError' on the arrays?

     

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.