Menu

False positive on MISRA 18.8

2021-03-02
2021-03-03
  • Marco Ferragatta

    Hello,
    before all, thank you for this great software!

    Running the software I got some false positives, and one of them is related to MISRA 18.8 rule.
    When the length of an array is determined using a #define I get the rule violation. It seems related to some sort of preprocessing problem, in fact if the #define is in the same file in which the array is declared there is no error. Otherwise, if the #define is located in a header which will be included, the rule violation is raised.
    In my embedded project I have to deal with a large amount of generated code, that I can't modify, which make a wide use of #defines that recall to other #defines in another include file.

    I have attached a small project that reproduces the error.

    I've tried to launch the tests from command line also, this is the result:

            C:\Program Files\Cppcheck>cppcheck -rp --addon="C:\Program Files\Cppcheck\addons\misra.json" C:\Temp\Test_CppCheck\Sources -I C:\Temp\Test_CppCheck\Sources
            Checking C:\Temp\Test_CppCheck\Sources\main.c ...
            Checking C:\Temp\Test_CppCheck\Sources\main.c: DEFINESL1_H...
            Checking C:\Temp\Test_CppCheck\Sources\main.c: DEFINESL2_H...
            main.c:8:17: style: Required: Variable-length array types shall not be used. [misra-c2012-18.8]
    
                            ^
            main.c:7:17: style: Required: Variable-length array types shall not be used. [misra-c2012-18.8]
    
                            ^
    

    Finally, if check the configuration from command line, I got no errors:

            C:\Program Files\Cppcheck>cppcheck -rp --check-config --addon="C:\Program Files\Cppcheck\addons\misra.json" C:\Temp\Test_CppCheck\Sources -I C:\Temp\Test_CppCheck\Sources
            Checking C:\Temp\Test_CppCheck\Sources\main.c ...
    
            C:\Program Files\Cppcheck>
    
     
  • Georgiy Komarov

    Georgiy Komarov - 2021-03-03

    Hello, Marco,

    Thanks for reporting this. I can confirm this false positive.

    I created the following ticket: https://trac.cppcheck.net/ticket/10197

     
  • Marco Ferragatta

    Hello Georgiy,
    thanks to you for taking into account my report.
    Checking the embedded code of my application I've found other cases: for some of them I'm pretty sure they are false positives, for some others I'm suspicious. Now I'm a little busy at work, but as soon as I've some time I will provide a separate report for each of them with attached a simple project that can reproduce the false positive (or the suspicious one).

    Have a nice day!

     
    👍
    2

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.