Menu

Error: Failed to load misra.json

2022-06-17
2022-06-23
  • Nolan Bridges

    Nolan Bridges - 2022-06-17

    Hello,

    I have been trying to get the MISRA addon to work in CppCheck and I keep getting "Failed to load misra.json". I've attached my CMD output. The first output is when I have misra.json in the CppCheck addons folder, and the second is when I moved misra.json into the folder that cmd is in. I also got the second cmd error when I changed --addons to the full path of misra.json and left it in the CppCheck addons folder.

    In the GUI when I try to scan this directory with one test file in it with the MISRA addon, it will show the normal CppCheck errors but then completely crash and close.

    I have attached screenshots of my misra.json and the Misra rules so you can see the format I used for that as well (edited out the rules themselves).

    If you need more information let me know, hopefully this is an easy fix!

    Best regards,
    Nolan

     
  • Daniel Marjamäki

    Not sure. Looks correct to me. Can you test what happens if you put the rule texts file in another path that does not have spaces?

     
  • Nolan Bridges

    Nolan Bridges - 2022-06-20

    I moved the rule text file to another location without spaces and now I'm getting this error (see attached):

     
    • Daniel Marjamäki

      the problem with that is there is a space after the --rule-texts=. The filename should be specified directly. If you want to share more dumps can you please copy paste the text instead it's a bit clumpsy with the screenshots.

       
  • Nolan Bridges

    Nolan Bridges - 2022-06-20

    Thank you for your response Daniel. That did work but now I'm getting this as output in my text file. This is an example of a few lines:

    misra-test.c:214:18: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-4.2]
        (void)printf("??=Trigraph\n");   // 4.2
                     ^
    misra-test.c:264:16: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-6.1]
      int          d:2; // 6.1 - plain int not compliant
                   ^
    misra-test.c:267:16: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-6.2]
      signed int   h:1; // 6.2 - signed int with size 1 is not compliant
                   ^
    misra-test.c:278:11: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-7.1]
      int x = 066; // 7.1
              ^
    misra-test.c:283:18: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-7.2]
        uint32_t b = 0x80000000; // 7.2
                     ^
    misra-test.c:298:22: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-7.3]
      long misra_7_3_a = 0l; //7.3
                         ^
    

    Any ideas? I've only removed that space so everything else is the same.

    Thanks,
    Nolan

     
  • Nolan Bridges

    Nolan Bridges - 2022-06-20

    Thank you for your response Daniel. That did work but now I'm getting this as output in my text file. This is an example of a few lines:

    misra-test.c:214:18: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-4.2]
        (void)printf("??=Trigraph\n");   // 4.2
                     ^
    misra-test.c:264:16: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-6.1]
      int          d:2; // 6.1 - plain int not compliant
                   ^
    misra-test.c:267:16: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-6.2]
      signed int   h:1; // 6.2 - signed int with size 1 is not compliant
                   ^
    misra-test.c:278:11: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-7.1]
      int x = 066; // 7.1
              ^
    misra-test.c:283:18: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-7.2]
        uint32_t b = 0x80000000; // 7.2
                     ^
    misra-test.c:298:22: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-7.3]
      long misra_7_3_a = 0l; //7.3
                         ^
    

    Any ideas? I've only removed that space so everything else is the same.

    Thanks,
    Nolan

     
  • Daniel Marjamäki

    Hmm. Obviously the misra rule texts does not work properly.

    Can you write a "m.txt" file with this contents:

    Appendix A Summary of guidelines
    Rule 4.2 Required
    R4.2 text.
    Rule 6.1 Required
    R6.1 text.
    Rule 6.2 Mandatory
    R6.2 text.
    Rule 7.1 Advisory
    R7.1 text.
    Rule 7.2 Advisory
    R7.2 text.
    Rule 7.3 Required
    R7.3 text.
    

    If you use that "m.txt" file you should get different texts.

    For your information if your company purchase the Cppcheck Premium license (https://www.cppchecksolutions.com), you don't need to configure the rules texts like this. The Cppcheck Premium provides proper misra rules texts.

     
  • Nolan Bridges

    Nolan Bridges - 2022-06-21

    Thank you for the information! I will consider a license.

    I created the m.txt file but was unable to get a change in output. It still says "(use --rule-texts to get proper output)" for the rules that you had me put in the text file.

     

    Last edit: Nolan Bridges 2022-06-21
    • Daniel Marjamäki

      More basic then.

      Source code:

      void foo() {}
      

      Put that in file "1.c".

      Commands:

      cppcheck --dump 1.c
      python "C:\Program Files\Cppcheck\addons\misra.py" --rule-texts=m.txt 1.c.dump
      

      I expect some such output:

      [1.c:2] (style) misra violation 802 with no text in the supplied rule-texts-file (Undefined) [misra-c2012-8.2]
      [1.c:2] (style) misra violation 804 with no text in the supplied rule-texts-file (Undefined) [misra-c2012-8.4]

       
  • Nolan Bridges

    Nolan Bridges - 2022-06-23

    I ran that and this is the output I received:

    [1.c:1] (style) misra violation 802 with no text in the supplied rule-texts-file (Undefined) [misra-c2012-8.2]
    [1.c:1] (style) misra violation 804 with no text in the supplied rule-texts-file (Undefined) [misra-c2012-8.4]
    Traceback (most recent call last):
      File "C:\Program Files\Cppcheck\addons\misra.py", line 4704, in <module>
        main()
      File "C:\Program Files\Cppcheck\addons\misra.py", line 4638, in main
        checker.parseDump(item)
      File "C:\Program Files\Cppcheck\addons\misra.py", line 4222, in parseDump
        data = cppcheckdata.parsedump(dumpfile)
      File "C:\Program Files\Cppcheck\addons\cppcheckdata.py", line 1220, in parsedump
        return CppcheckData(filename)
      File "C:\Program Files\Cppcheck\addons\cppcheckdata.py", line 1026, in __init__
        for event, node in ElementTree.iterparse(self.filename, events=('start', 'end')):
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\xml\etree\ElementTree.py", line 1274, in iterparse
        next(it)
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\xml\etree\ElementTree.py", line 1251, in iterator
        source = open(source, "rb")
    PermissionError: [Errno 13] Permission denied: '.'
    
     
  • Nolan Bridges

    Nolan Bridges - 2022-06-23

    Update: Yes, it was the " . " in the command that was causing the traceback, I think I got the rule text working, I just need to reformat everything.

    I'm running this command after the cppcheck dump command, maybe the " . " in the command before the "2" is causing the error?

    python "C:\Program Files\Cppcheck\addons\misra.py" --rule-texts=C:/misra/misrarules.txt misra-test.c.dump . 2>err.txt
    
     

    Last edit: Nolan Bridges 2022-06-23
  • Nolan Bridges

    Nolan Bridges - 2022-06-23

    So I got the rules texts to work fine and the rule text displays next to the error, thank you so much for all of your help!

    However, I would like to use the GUI to scan many files, but when running it, the severity only shows style for all of the MISRA violations, and not Advisory, Mandatory, or Required. Would you happen to know how to fix this?

     

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.