Menu

MISRA Error On Multiple Files

Amir
2021-04-12
2021-04-13
  • Amir

    Amir - 2021-04-12

    Hello,
    I've been trying to resolve a problem I've been having with cppcheck for the past few months, and I think I have pinpointed where the issue is. I've been getting errors like this:

    When I execute this:

    cppcheck --addon=misra.json -rp --inline-suppr --addon-python=python ..\..\Sources\asw\
    

    I'm getting errors like this:

    Bailing out from checking ..\..\Sources\asw\aswFaults.c since there was an internal error: Failed to execute 'python "C:\Program Files\Cppcheck\addons\misra.py" --cli --rule-texts=misra_rules.txt --suppress-rules 17.8 ..\..\Sources\asw\aswFaults.c.dump'. Traceback (most recent call last):
      File "C:\Program Files\Cppcheck\addons\misra.py", line 3327, in <module>
        main()
      File "C:\Program Files\Cppcheck\addons\misra.py", line 3271, in main
        checker.parseDump(item)
      File "C:\Program Files\Cppcheck\addons\misra.py", line 3106, in parseDump
        self.executeCheck(905, self.misra_9_5, cfg, data.rawTokens)
      File "C:\Program Files\Cppcheck\addons\misra.py", line 3053, in executeCheck
        check_function(*args)
      File "C:\Program Files\Cppcheck\addons\misra.py", line 1508, in misra_9_5
        misra_9.misra_9_x(self, data, 905, rawTokens)
      File "C:\Program Files\Cppcheck\addons\misra_9.py", line 405, in misra_9_x
        ed = getElementDef(nameToken, rawTokens)
      File "C:\Program Files\Cppcheck\addons\misra_9.py", line 420, in getElementDef
        createArrayChildrenDefs(ed, nameToken.astParent, rawTokens)
      File "C:\Program Files\Cppcheck\addons\misra_9.py", line 431, in createArrayChildrenDefs
        foundToken = next(rawToken for rawToken in rawTokens if rawToken.file == token.file and rawToken.linenr == token.linenr and rawToken.column == token.column)
    StopIteration
    

    When I posted this error before you guys didn't see an issue because I uploaded the file that was causing the issue and you ran it on that 1 file. If I do the same, it works:

    Run:

    cppcheck --addon=misra.json -rp --inline-suppr --addon-python=python ..\..\Sources\asw\aswFaults.c
    

    Result:

    Checking ..\..\Sources\asw\aswFaults.c ...
    ..\..\Sources\asw\aswFaults.c:279:5: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     if (Asw_1msStopWatchElapsed(setFaultTimer[fault], setTime))
        ^
    ..\..\Sources\asw\aswFaults.c:283:10: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     else if (Asw_1msStopWatchElapsed(clearFaultTimer[fault], clearTime))
             ^
    ..\..\Sources\asw\aswFaults.c:363:5: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     if (Asw_1msStopWatchElapsed(setFaultTimer[fault], setTime))
        ^
    ..\..\Sources\asw\aswFaults.c:367:10: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     else if (Asw_1msStopWatchElapsed(clearFaultTimer[fault], clearTime))
             ^
    ..\..\Sources\asw\aswFaults.c:447:5: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     if (Asw_1msStopWatchElapsed(setFaultTimer[fault], setTime))
        ^
    ..\..\Sources\asw\aswFaults.c:451:10: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     else if (Asw_1msStopWatchElapsed(clearFaultTimer[fault], clearTime))
             ^
    ..\..\Sources\asw\aswFaults.c:531:5: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     if (Asw_1msStopWatchElapsed(setFaultTimer[fault], setTime))
        ^
    ..\..\Sources\asw\aswFaults.c:535:10: style: Required. The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. [misra-c2012-14.4]
     else if (Asw_1msStopWatchElapsed(clearFaultTimer[fault], clearTime))
             ^
    

    It seems like its an issue when I try to run cppcheck on multiple files as follows:

    cppcheck --addon=misra.json -rp --inline-suppr --addon-python=python ..\..\Sources\asw\
    

    which is causing the python errors. I've zipped up the folder and attached it so maybe you can run and see if you are seeing the same thing. I'm seeing python errors across multiple files in the folder. I'm using the latest cppcheck (2.4.1) with misra.py from the 2.4.1 tag also.

     
  • Georgiy Komarov

    Georgiy Komarov - 2021-04-13

    Thanks! This PR should fix the error: https://github.com/danmar/cppcheck/pull/3208 .

     

    Last edit: Georgiy Komarov 2021-04-13
  • Martin Hohl

    Martin Hohl - 2021-04-13

    Removed my posting, because it was an erroneous off-topic posting, sorry.

     

    Last edit: Martin Hohl 2021-04-13
  • Amir

    Amir - 2021-04-13

    thank you guys! This has been a sore spot for a while now.

     

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.