Menu

MISRA-Check: How to include project includes

2021-08-24
2022-02-17
  • Karsten Beck

    Karsten Beck - 2021-08-24

    Hello folks,

    we are using CppCheck and the MISRA check in conjunction with IAR Workbench for ARM.
    Include paths can be specified in the Project Settings, which is what we use.
    Unfortunately the MISRA-Check does not take over these includes and so some defines are not known to it and it reports an error.

    What is the best way to inform MISRA-Check about these include paths?

    Greetings
    Karsten

     
  • Daniel Marjamäki

    The best way would be to add a IAR Workbench project import into Cppcheck.

    Do you have a small sample project with include paths and defines?

    If it is possible to convert the IAR workbench project into a compile_commands.json then that can be imported into cppcheck directly.

     
    • Karsten Beck

      Karsten Beck - 2021-08-24

      Hi Daniel,
      thanks for your quick reply.
      I have attached a sample file for you, which contains both the defines (starting at line 222) and the includes (starting at line 351). The .ewp file is a .xml file.
      Kind regards
      Karsten

       
      • Daniel Marjamäki

        ok thanks! for information, I do not have time to look at this in the near future. I wonder if you could look at it. I do not expect that it will be very difficult. And it would be good if you do it because you can test it on real projects also.
        Here is similar code: https://github.com/danmar/cppcheck/blob/main/lib/importproject.cpp#L1067

        You would need to write a corresponding function that will import the data from your ewp file.

        Compiling cppcheck is easy. You just need a C++ compiler. There is no required dependency.

         
      • Daniel Marjamäki

        For your information I have created this trac ticket: https://trac.cppcheck.net/ticket/10428

         
    • Karsten Beck

      Karsten Beck - 2021-11-22

      Hey Daniel,
      with version 9 of IAR Workbench it is possible to create a json-file directly from the project.
      I tried to load it in cppcheck:
      cppcheck.exe" --project="D:\compile_commands.json".
      But unfortunately I get an error message that I can't do much with:
      "type mismatch! call is<type>() before get<type>()" && is<std::string>()
      Is the error in the json-file? How can I search for the cause?</std::string></type></type>

      Best regards
      Karsten
      
       

      Last edit: Karsten Beck 2021-11-22
      • Daniel Marjamäki

        with version 9 of IAR Workbench it is possible to create a json-file directly from the project.

        Very interesting!

        Is the error in the json-file? How can I search for the cause?

        maybe this can help:

        https://jsonlint.com/

         
        • Karsten Beck

          Karsten Beck - 2021-11-23

          Valid JSON
          Could it be an import error in Cppchecker after all?

           
          • Daniel Marjamäki

            Yes probably a bug in Cppcheck. Sounds like it expects that some value somewhere is a string and it's something else. I wonder if you volounteer to bisect it? you could remove some file entries from the json and see if it crashes.. or feel free to compile and trouble shoot..

             
            • Karsten Beck

              Karsten Beck - 2022-01-31

              After some time I got back to analyze the problem a bit.
              Apparently the error is caused by the use of the square brackets ( "[" and "]"). As soon as they are used, the error "type mismatch! call is<type>() before get<type>()" && is<std::string>()" occurs.
              Do you have another idea? I'm not that good at C#, unfortunately.</std::string></type></type>

               
              • Daniel Marjamäki

                It feels like that has been discussed and worked on not too long ago somewhere. either somewhere in this forum or there was a PR...

                 
                • Daniel Marjamäki

                  I guess I was thinking about this:

                  https://github.com/danmar/cppcheck/pull/3667

                  well not 100% the same but related. Can you show an example compile database that cppcheck has problems with.

                   
                  • Karsten Beck

                    Karsten Beck - 2022-02-02

                    Of course. Gladly.

                     
                    • Karsten Beck

                      Karsten Beck - 2022-02-15

                      @danielmarjamaki Could I help you with my example? How can we fix the error?

                       

                      Last edit: Karsten Beck 2022-02-15
                      • Daniel Marjamäki

                        That example is weird. I don't see a compile command. And there is no "file" field. Did you just extract this entry because Cppcheck has problems with this? And there are more entries that are "proper"?

                         
                        • Karsten Beck

                          Karsten Beck - 2022-02-16

                          Yes, I did. I deleted always more to locate the error.

                           
                          • Daniel Marjamäki

                            ok thanks for explanation. that is good.

                             
                      • Daniel Marjamäki

                        I have pushed a possible fix:
                        https://github.com/danmar/cppcheck/commit/c968aeaf73d4b1767e6886200baca31c3341a3f3

                        Can you try it out? For information there is a nightly build here:
                        https://github.com/danmar/cppcheck/actions/workflows/release-windows.yml
                        The fix will be provided in build 684.

                         
                        • Karsten Beck

                          Karsten Beck - 2022-02-17

                          Ok, I saw what build 684 was built tonight. I may be obviously blind, but where can I download this build as an installfile?

                           
                          • CHR

                            CHR - 2022-02-17

                            https://github.com/danmar/cppcheck/actions/workflows/release-windows.yml
                            You must be logged in to download the installer.

                             
                            • Karsten Beck

                              Karsten Beck - 2022-02-17

                              Ahhh, I am a goofball ;-)

                               
                        • Karsten Beck

                          Karsten Beck - 2022-02-17

                          @danielmarjamaki I have just installed the build 684 and tried it with it: the JSON file can now be read successfully.
                          So far first THANK YOU!

                           
  • Daniel Marjamäki

    For information, if your company would be interested to pay for development of this feature let me know.

     
    • Karsten Beck

      Karsten Beck - 2021-08-27

      I will ask about it, but unfortunately do not have much hope.

       

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.