Menu

Possible False Positive Misra rule 8.4

vix
2024-01-30
2024-01-31
  • vix

    vix - 2024-01-30

    I enabled Misra C 2012 extension through the GUI of CppCheck 2.12.
    I cannot use CppCheck 2.13 for this issue

    This is my code:
    my_file.h

    #ifndef MY_FILE_H__
    #define MY_FILE_H__
    int foo(int a);
    #endif
    

    my_file.c

    #include "my_file.h"
    
    int foo(int a)
    {
        return a;
    }
    

    But I ge the violation of misra rule 8.4.
    I think this should be a Misra 2012 rule 8.4 (not Misra 2004), but here I can see Misra 2012 rules
    https://www.ibm.com/docs/en/devops-test-embedded/8.2.0?topic=review-code-misra-2012-rules
    And it should be

    A prototype for the global function '%name%' should be declared before defining the function

    But as far as I understand, the prototype is in the .h file.
    So I cannot understand the reason.

    Another tool, that supports Misra 2004 only, notifies me about violation of rule 8.1

    Functions shall have prototype and prototype shall be visible at both the definition and call

    Are these false positve?
    Or is there a way to fix this?

     
  • vix

    vix - 2024-01-30

    Is it possible that this happens because the path of the folder including my_file.h has not been added to cppcheck include paths?
    And so the addon doesn't find the file and this produces this behavior?

     
  • Daniel Marjamäki

    yes if you didn't add the include path for my_file.h explicitly then it is very likely.

     

    Last edit: Daniel Marjamäki 2024-01-31
    • Daniel Marjamäki

      In the normal cppcheck analysis I normally don't want that missing declarations leads to false positives. I consider it the recommended and usual case that users do not provide all the include paths for all headers.

      In misra checking we have a bit more strict checking because it's used in safety. I think that:
      * false positives are not "wanted" but it's better than false negatives. I consider a false positive to be "safe" as it will give you a hint you need to solve something.
      * false negatives are not safe. If a misra checker does not know if there is a problem or not because of missing configuration, my intention is that a "misra-config" message will be written.

       

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.