Menu

Command Line using GUI-project: misra violation (use --rule-texts=<file> to get proper output)

2024-11-08
2024-11-20
  • Cpp Checker

    Cpp Checker - 2024-11-08

    I want use cppcheck premium with its graphical user interface as well in a pipeline with it's command line functionality. While using the GUI version everything works well.

    When I am reusing the GUI project to run the analysis with the git bash or windows powershell by using the following command:

    cppcheck --project=guiproject.cppcheck --enable=style --xml 2> output.xml

    all misra findings have the following description:

    misra violation (use --rule-texts=<file> to get proper output)</file>

    Analysing the project without reusing the GUI project file, the message/summary of of the misra finding is correctly displayed.

    How can I fix that? Is this a faulty configuration?

    Prerequisites:
    Windows 10 Pro 22H2
    Powershell version: 5.1.19041.5007
    Git version: git version 2.43.0.windows.1
    CppCheck Premium: 24.9.0.1
    Python: 3.12.2

     
  • Daniel Marjamäki

    That is confusing. Are you sure that when you execute cppcheck on the command line that it executes the premium binary? If you write cppcheck --version does it say Cppcheck Premium 24.9.0.1

     
  • Cpp Checker

    Cpp Checker - 2024-11-12

    I just double checked...

    PS C:\> cppcheck --version
    Cppcheck Premium 24.9.0.1
    
     
  • Daniel Marjamäki

    let's do it simple.. what happens if you execute cppcheck analysis without using the project file.

    cppcheck --premium=misra-c-2023 somefile.c
    

    a guess, it's possible there are cached results in the cppcheck build dir. so I would suggest that is removed for now.

    would it feel ok to share the cppcheck project file here? feel free to obfuscate the paths..

     
  • Daniel Marjamäki

    For your info I get this output on a small simple testfile:

    PS C:\Users\Administrator\test1> type test1.c
    
    void f();
    
    PS C:\Users\Administrator\test1> & 'C:\Program Files\Cppcheck premium\cppcheck.exe' --premium=misra-c-2023 test1.c
    Checking test1.c ...
    test1.c:2:7: style: Function types shall be in prototype form with named parameters [misra-c2023-8.2]
    void f();
          ^
    nofile:0:0: information: Active checkers: 395/1035 (use --checkers-report=<filename> to see details) [checkersReport]
    

    I would assume you can reproduce that..

     
  • Cpp Checker

    Cpp Checker - 2024-11-14

    I can reproduce your example:

    cppcheck --premium=misra-c-2023 test1.c
    Checking test1.c ...
    test1.c:1:7: style: Function types shall be in prototype form with named parameters [misra-c2023-8.2]
    void f();
          ^
    nofile:0:0: information: Active checkers: 395/1035 (use --checkers-report=<filename> to see details) [checkersReport]
    

    Here is the content of the .cppcheck-file I used. I obfuscated path names with some-path

    <?xml version="1.0" encoding="UTF-8"?>
    <project version="1">
        <builddir>some-path</builddir>
        <platform>win32A</platform>
        <analyze-all-vs-configs>false</analyze-all-vs-configs>
        <check-headers>true</check-headers>
        <check-unused-templates>true</check-unused-templates>
        <inline-suppression>false</inline-suppression>
        <max-ctu-depth>5</max-ctu-depth>
        <max-template-recursion>100</max-template-recursion>
        <includedir>
             <dir name="some-path"/>
        </includedir>
        <defines>
            <define name="FUNC(rettype, memclass) rettype"/>
        </defines>
        <paths>
            <dir name="some-path"/>
        </paths>
        <suppressions>
            <suppression>misra-config</suppression>
        </suppressions>
        <addons>
            <addon>misra</addon>
        </addons>
        <check-level-exhaustive/>
        <bug-hunting/>
        <project-name>cpp_check_premium_test_01</project-name>
    </project>
    

    Using this configuration without the directories in the include dir section, I get the following output:

    cppcheck --project=cppcheck_config.cppcheck --enable=style
    Checking test1.c ...
    Checking test1.c: FUNC(rettype, memclass) rettype...
    test1.c:1:7: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-8.2]
    void f();
          ^
    nofile:0:0: information: Active checkers: 307/1035 (use --checkers-report=<filename> to see details) [checkersReport]
    
     
  • Daniel Marjamäki

    Thanks for your quick answers.

    In your project file I would like that you remove this line:

        <builddir>some-path</builddir>
    

    So we make sure that you are not just looking at cached results.

    And I think you should change the define to:

        <define name="FUNC(rettype,memclass)=rettype"/>
    

    I believe this will improve the analysis but this will not make the rule text proper.

    One more thing you could try would be to run similar analysis on the command line without using the project file at all:

    cppcheck -Isome-path -D "FUNC(rettype,memclass)=rettype" --premium=misra-c-2012 some-path
    
     

    Last edit: Daniel Marjamäki 2024-11-15
  • Cpp Checker

    Cpp Checker - 2024-11-20

    With the simple test file and this .cppcheck config

    <?xml version="1.0" encoding="UTF-8"?>
    <project version="1">
        <platform>win32A</platform>
        <analyze-all-vs-configs>false</analyze-all-vs-configs>
        <check-headers>false</check-headers>
        <check-unused-templates>true</check-unused-templates>
        <inline-suppression>false</inline-suppression>
        <max-ctu-depth>2</max-ctu-depth>
        <max-template-recursion>100</max-template-recursion>
        <includedir>
        </includedir>
        <defines>
            <define name="FUNC(rettype, memclass)=rettype"/>
        </defines>
        <paths>
            <dir name="some-path"/>
        </paths>
        <addons>
            <addon>misra</addon>
        </addons>
        <project-name>cpp_check_premium_test_01</project-name>
    </project>
    

    I get the following output:

    cppcheck --project=cppcheck_config.cppcheck --enable=style
    Checking test1.c ...
    Checking test1.c: FUNC(rettype, memclass)=rettype...
    test1.c:1:7: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-8.2]
    void f();
          ^
    nofile:0:0: information: Active checkers: 307/1035 (use --checkers-report=<filename> to see details) [checkersReport]
    

    Concerning your other proposal:

    cppcheck -Isome-path -D "FUNC(rettype,memclass)=rettype" --premium=misra-c-2012 some-path
    

    has the proper output

    Checking test1.c ...
    Checking test1.c: FUNC(rettype,memclass)=rettype...
    test1.c:1:7: style: Function types shall be in prototype form with named parameters [misra-c2012-8.2]
    void f();
          ^
    nofile:0:0: information: Active checkers: 395/1035 (use --checkers-report=<filename> to see details) [checkersReport]
    
     

    Last edit: Cpp Checker 2024-11-21

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.