Menu

Ignore unwanted code from analysis

2019-09-10
2019-12-09
  • Rohit Kotak

    Rohit Kotak - 2019-09-10

    Hi,

    I am integrating cppcheck in my project for static analysis of the code. I am using below command to perform analysis but not able to ignore the code from the directories provided with -i option.

    cppcheck.exe --enable=warning --enable=style --enable=performance 
        -ishared/open/l6-hardware-abstraction-layer-sm/source/vendor/
        -ishared/open/l6-hardware-abstraction-layer-sm/source/device/
        -ishared/open/l6-hardware-abstraction-layer-sm/source/legacy/
        -ishared/open/l6-hardware-abstraction-layer-sm/source/startup/
        -ishared/open/l5-rtos-layer-sm/
        --project=${PROJECT_BINARY_DIR}/compile_commands.json
    

    Please help me to ignore code from these directories.

    Regards,
    Rohit

     
  • orbitcowboy

    orbitcowboy - 2019-09-10

    Did you try to insert a space between -i and the path to be ignored?

     
  • Rohit Kotak

    Rohit Kotak - 2019-09-11

    Yes. It is correct without space. But --project option and -i option are not working together. I want to use --project and also want to ignore the unwanted code from some directories.

     
  • Daniel Marjamäki

    There was a discussion in the chat that you missed. I think we should fix -i for 1.90.

    We can reproduce this in the cppcheck repo with:

    $ ./cppcheck -iexternals --project=lib/cppcheck.vcxproj
    
     
  • Rohit Kotak

    Rohit Kotak - 2019-11-08

    Hi Daniel, Any update on this issue? Any idea about release date of 1.90?

     
  • Daniel Marjamäki

    Somehow I forogt about it. I have created https://trac.cppcheck.net/ticket/9463 and intend to fix that.

    Any idea about release date of 1.90?

    My feeling right now is ~1 month. I can only give a rough guess.

     
  • Rohit Kotak

    Rohit Kotak - 2019-11-08

    Okay Daniel. Thank you for the update.

     
  • Daniel Marjamäki

    hmm.. is it possible for you to test latest cppcheck? When I try ./cppcheck -iexternals --project=lib/cppcheck.vcxproj then the files in externals are ignored. But I have a strong feeling that this did not work a month ago. It feels like this was fixed but I am not sure when that happened.

     
  • Daniel Marjamäki

    I tried cppcheck-1.89 now.. and that seems to ignore paths also. not sure how to reproduce the problem.

     
  • Daniel Marjamäki

    I close the ticket. I can't reproduce. If you still have problems.. it would be good if you can help us reproduce.

     
    • Rohit Kotak

      Rohit Kotak - 2019-12-09

      Hi Daniel, I was facing this issue because I was providing relative path of the directory which I wanted to exclude. It is working if I provide absolute path.

      Thank you.

       
  • Francesc Elies

    Francesc Elies - 2019-12-06

    If I execute the following command with cppcheck compiled from 7da68bff7b99e6d142591b30b0c25804a4a1da4a CommitDate: Thu Dec 5 18:25:50 2019 +0300

    .\bin\cppcheck.exe -iexternals --project=lib/cppcheck.vcxproj --enable=all --xml-version=2 2> result-externals-shall-be-ignored.xml
    

    I see lines like:

            <error id="noExplicitConstructor" severity="style" msg="Class &apos;XMLDeclaration&apos; has a constructor with 1 argument that is not explicit." verbose="Class &apos;XMLDeclaration&apos; has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided." cwe="398">
                <location file0="lib\analyzerinfo.cpp" file="externals\tinyxml\tinyxml2.h" line="1073" column="5"/>
                <symbol>XMLDeclaration</symbol>
            </error>
    

    What is the difference between file0 and file? In file appears externals, should this be there?

    Daniel, do you think this might be related or do I miss something?

    Best & thanks

     
  • Daniel Marjamäki

    The file0 specify what file is checked to get this error. This information is used in the GUI. If you generate a html report or text report then file0 is probably not interesting.

     
  • Daniel Marjamäki

    hmm.. the -i does not mean "suppress warnings in ..." nor "prevent #include for files in...".

    The cppcheck --help is not crystal clear:

    -i <dir or file>     Give a source file or source file directory to exclude
                         from the check. This applies only to source files so
                         header files included by source files are not matched.
    

    Maybe we can clarify it. Please feel free to suggest improvements.

    If you run cppcheck like this: cppcheck -Ifoo -ifoo file1.cpp then if file1.cpp includes headers in foo then those headers will be included and analyzed and warnings will be written.

    If you run cppcheck like this cppcheck -ifoo . then no source files in foo will be checked. For instance if there is a file "foo/1.cpp" then that file will not be checked. However if there is a file in the current path ./file1.cpp that contains #include "foo/1.h" then that header will be included and analyzed and you will get warnings.

    So.. -i does not affect what files we include when there are #include directives in the code.

     
  • Francesc Elies

    Francesc Elies - 2019-12-09

    Examples are always great, would you have something agains including that example inside the --help string?
    I would gladly open a PR, what do you think.

     

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.