Menu

--project with --dump skips headers

2024-06-11
2024-06-13
  • Mark Jansen

    Mark Jansen - 2024-06-11

    When creating a dump with the '--dump' option, header files are skipped.
    When analyzing the code, the headers seem to be included, because issues in the headers are found.

    Is this an omission from the '--dump' option?

    mark@dev3:~/cppcheck_test/build$ cppcheck --project=compile_commands.json --dump
    Checking /home/mark/cppcheck_test/main.cpp ...
    1/2 files checked 50% done
    Checking /home/mark/cppcheck_test/test.cpp ...
    /home/mark/cppcheck_test/test.h:7:12: error: Null pointer dereference: (int*)0 [nullPointer]
     int i = *((int*)0);
               ^
    2/2 files checked 100% done
    Active checkers: 59/565
    mark@dev3:~/cppcheck_test/build$ ll ..
    total 44
    drwxrwxr-x  3 mark mark  4096 Jun 11 12:10 ./
    drwxr-xr-x 39 mark mark  4096 Jun 11 12:09 ../
    drwxrwxr-x  3 mark mark  4096 Jun 11 12:09 build/
    -rw-r--r--  1 mark mark   122 Jun 11 12:09 CMakeLists.txt
    -rw-r--r--  1 mark mark     0 Jun 11 12:08 main.cpp
    -rw-rw-r--  1 mark mark   300 Jun 11 12:10 main.cpp.dump
    -rw-r--r--  1 mark mark    75 Jun 11 12:08 test.cpp
    -rw-rw-r--  1 mark mark 13549 Jun 11 12:10 test.cpp.dump
    -rw-r--r--  1 mark mark   128 Jun 11 12:08 test.h
    
     

    Last edit: Mark Jansen 2024-06-11
  • Daniel Marjamäki

    hm.. the raw tokens in headers are not listed. This is true.

    However "non-raw" tokens in headers are listed in the "tokenlist".

    It does seem unfortunate to me however how much bigger would the dump files be if we included all raw tokens for all headers also..

     
    • Mark Jansen

      Mark Jansen - 2024-06-12

      But in the current form, there are no .dump files generated for project headers,
      so addons also cannot process headers.

       
      • Daniel Marjamäki

        dumpfiles are not created for every header by design.

        $ cat 1.c
        #include "1.h"
        a=1;
        $ cat 1.h
        #define X 123
        h=1;
        

        The dumpfile for 1.c contains the tokens in the headers :

          <tokenlist>
            <token id="5598d2618460" file="1.h" linenr="4" column="1" str="h" scope="5598d2611bf0" type="name" astParent="5598d2616bc0"/>
            <token id="5598d2616bc0" file="1.h" linenr="4" column="2" str="=" scope="5598d2611bf0" type="op" isAssignmentOp="true" values="5598d26026f0" astOperand1="5598d2618460" astOperand2="5598d2616c20"/>
            <token id="5598d2616c20" file="1.h" linenr="4" column="3" str="1" scope="5598d2611bf0" type="number" isInt="true" values="5598d26026b0" astParent="5598d2616bc0" valueType-type="int" valueType-sign="signed" valueType-reference="None"/>
            <token id="5598d2617c00" file="1.h" linenr="4" column="4" str=";" scope="5598d2611bf0"/>
            <token id="5598d2617c60" file="1.c" linenr="4" column="1" str="a" scope="5598d2611bf0" type="name" astParent="5598d2617ce0"/>
            <token id="5598d2617ce0" file="1.c" linenr="4" column="2" str="=" scope="5598d2611bf0" type="op" isAssignmentOp="true" values="5598d2602770" astOperand1="5598d2617c60" astOperand2="5598d2617d40"/>
            <token id="5598d2617d40" file="1.c" linenr="4" column="3" str="1" scope="5598d2611bf0" type="number" isInt="true" values="5598d2602730" astParent="5598d2617ce0" valueType-type="int" valueType-sign="signed" valueType-reference="None"/>
            <token id="5598d26123b0" file="1.c" linenr="4" column="4" str=";" scope="5598d2611bf0"/>
          </tokenlist>
        
         

        Last edit: Daniel Marjamäki 2024-06-12
        • Daniel Marjamäki

          hmm I changed my mind and the <rawtoken> will not contain the raw tokens for the headers.

           
          • Mark Jansen

            Mark Jansen - 2024-06-13

            I did miss that the tokenlist does contain the tokens for headers,
            for my use case this should probably be enough.

            In a bigger project this means a lot of duplicated data, but if that is not an issue I guess there is no change needed in cppcheck.

             
  • Daniel Marjamäki

     

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.