Menu

misra addon crashes after update to cppcheck 2.8

mkep2000
2022-06-13
2022-06-20
  • mkep2000

    mkep2000 - 2022-06-13

    Hi,

    We are currently using cppcheck2.7 for our project written in C using , however when we updated to cppcheck2.8 the misra addon crashes. When reverting to 2.7, it does not crash anymore, so this is a regression.
    The error that appears (output from VS Code):

    [build] Failed to execute 'python3 /usr/share/cppcheck/addons/runaddon.py /usr/share/cppcheck/addons/misra.py --cli --rule-texts=/mnt/c/XXXXXXXXX/misrac-2012_rule-texts.txt --severity=warning --file-list /mnt/c/XXXXXXXXX/cppcheck-addon-ctu-file-list'. Traceback (most recent call last):
    [build]   File "/usr/share/cppcheck/addons/runaddon.py", line 8, in <module>
    [build]     runpy.run_path(addon, run_name='__main__')
    [build]   File "/usr/lib/python3.8/runpy.py", line 265, in run_path
    [build]     return _run_module_code(code, init_globals, run_name,
    [build]   File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    [build]     _run_code(code, mod_globals, init_globals,
    [build]   File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    [build]     exec(code, run_globals)
    [build]   File "/usr/share/cppcheck/addons/misra.py", line 4704, in <module>
    [build]     main()
    [build]   File "/usr/share/cppcheck/addons/misra.py", line 4627, in main
    [build]     dump_files, ctu_info_files = cppcheckdata.get_files(args)
    [build]   File "/usr/share/cppcheck/addons/cppcheckdata.py", line 1294, in get_files
    [build]     with open(args.file_list, 'rt') as f:
    [build] FileNotFoundError: [Errno 2] No such file or directory: '/mnt/c/XXXXXXXXXX/cppcheck-addon-ctu-file-list'
    
     
  • Daniel Marjamäki

    Strange! I don't know what goes wrong.
    Do you know what command cppcheck is executed with. Can you reproduce the same output on the normal command line?
    Can you see if there are files in /mnt/c/XXXXXXXXXX/

     
  • mkep2000

    mkep2000 - 2022-06-15

    Hi,

    All the /mnt/c/XXXXXXXXXX/ are different paths, so I should have written /mnt/c/XXXX /mnt/c/YYYY etc, but yes I can verify that there are files in all those paths. However I can´t find any file named cppcheck-addon-ctu-file-list, but perhaps it becomes cleaned up after crash?

    Running cppcheck command from terminal works fine. It´s only with cmake integration (used by setting CMAKE_C_CPPCHECK) the problem occurs.

     
    • Daniel Marjamäki

      However I can´t find any file named cppcheck-addon-ctu-file-list, but perhaps it becomes cleaned up after crash?

      Cppcheck removes that after analysis. It's unfortunate in this case :-(

      Running cppcheck command from terminal works fine. It´s only with cmake integration (used by setting CMAKE_C_CPPCHECK) the problem occurs.

      ok interesting I wonder what cmake does differently.

       
  • Daniel Marjamäki

    I assume your project is not open source?

    Can you reproduce same problems on some open source project? i.e. cppcheck.

    https://github.com/danmar/cppcheck/archive/refs/tags/2.8.tar.gz

    Simple commands to build:

    tar xzvf 2.8.tar.gz
    cd cppcheck-2.8
    mkdir build
    cd build
    cmake ..
    make

     
  • mkep2000

    mkep2000 - 2022-06-17

    The project is not open source indeed.

     
  • Daniel Marjamäki

    Can you clarify more how we reproduce. I am no expert on cmake. And I haven't used CMAKE_C_CPPCHECK .. that is not something that is provided by the cppcheck project.

    I have created a small helloworld project where I defined the CMAKE_C_CPPCHECK variable. It just compiles I see no cppcheck analysis.

     
    • Daniel Marjamäki

      danielm@debian:~/helloworld/build$ cmake ..
      -- The C compiler identification is GNU 10.2.1
      -- The CXX compiler identification is GNU 10.2.1
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /usr/bin/cc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /usr/bin/c++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- Configuring done
      -- Generating done
      -- Build files have been written to: /home/danielm/helloworld/build
      danielm@debian:~/helloworld/build$ make
      Scanning dependencies of target helloworld
      [ 50%] Building C object CMakeFiles/helloworld.dir/1.c.o
      Checking /home/danielm/helloworld/1.c ...
      [100%] Linking C executable helloworld
      [100%] Built target helloworld
      danielm@debian:~/helloworld/build$
      
       
  • Jens Yllman

    Jens Yllman - 2022-06-19

    Is it not so that CMAKE_C_CPPCHECK is a variable set by find_program() trying to see if cppcheck is available. And it might not even be in 'upstream' CMake yet. And CMAKE_C_CPPCHECK is supposed to contain the command line to run cppcheck. So it depends on the implementation to find cppcheck what it puts into CMAKE_C_CPPCHECK. So if you can get the content of CMAKE_C_CPPCHECK you will see how cppcheck is run.

     

    Last edit: Jens Yllman 2022-06-19
  • mkep2000

    mkep2000 - 2022-06-20

    I´m not sure how you mean that CMAKE_C_CPPCHECK migh not be 'upstream'? It is a feature in cmake since 3.10 release at least.
    But yes you can use find_program() to find the cppcheck binary.

    Here is my modified version of the cmake file which works to compile helloworld for me, but the previous example probably worked for Daniel's local build as well.

    cmake_minimum_required(VERSION 3.18)
    
    project(helloworld VERSION 1.0)
    
    set(CPPCHECK_ARGS_DEFAULT
        --enable=all
        --std=c99
        --template=gcc
        --inconclusive
        --inline-suppr
        --quiet
    )
    
    find_program(CPPCHECK_EXECUTABLE NAMES "cppcheck" REQUIRED)
    
    set(CMAKE_C_CPPCHECK "${CPPCHECK_EXECUTABLE}" ${CPPCHECK_ARGS_DEFAULT})
    
    add_executable(helloworld 1.c)
    

    If I run:

    cmake ..
    

    Then to build:

    cmake --build . -v
    

    I get the following output:

    /usr/local/bin/cmake -S/mnt/c/temp/helloworld/helloworld -B/mnt/c/temp/helloworld/helloworld/build --check-build-system CMakeFiles/Makefile.cmake 0
    /usr/local/bin/cmake -E cmake_progress_start /mnt/c/temp/helloworld/helloworld/build/CMakeFiles /mnt/c/temp/helloworld/helloworld/build//CMakeFiles/progress.marks
    /usr/bin/make  -f CMakeFiles/Makefile2 all
    make[1]: Entering directory '/mnt/c/temp/helloworld/helloworld/build'
    /usr/bin/make  -f CMakeFiles/helloworld.dir/build.make CMakeFiles/helloworld.dir/depend
    make[2]: Entering directory '/mnt/c/temp/helloworld/helloworld/build'
    cd /mnt/c/temp/helloworld/helloworld/build && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /mnt/c/temp/helloworld/helloworld /mnt/c/temp/helloworld/helloworld /mnt/c/temp/helloworld/helloworld/build /mnt/c/temp/helloworld/helloworld/build /mnt/c/temp/helloworld/helloworld/build/CMakeFiles/helloworld.dir/DependInfo.cmake --color=
    make[2]: Leaving directory '/mnt/c/temp/helloworld/helloworld/build'
    /usr/bin/make  -f CMakeFiles/helloworld.dir/build.make CMakeFiles/helloworld.dir/build
    make[2]: Entering directory '/mnt/c/temp/helloworld/helloworld/build'
    [ 50%] Building C object CMakeFiles/helloworld.dir/1.c.o
    /usr/local/bin/cmake -E __run_co_compile --cppcheck=/usr/bin/cppcheck --source=/mnt/c/temp/helloworld/helloworld/1.c -- /usr/bin/cc    -MD -MT CMakeFiles/helloworld.dir/1.c.o -MF CMakeFiles/helloworld.dir/1.c.o.d -o CMakeFiles/helloworld.dir/1.c.o -c /mnt/c/temp/helloworld/helloworld/1.c
    Checking /mnt/c/temp/helloworld/helloworld/1.c ...
    [100%] Linking C executable helloworld
    /usr/local/bin/cmake -E cmake_link_script CMakeFiles/helloworld.dir/link.txt --verbose=1
    /usr/bin/cc CMakeFiles/helloworld.dir/1.c.o -o helloworld
    make[2]: Leaving directory '/mnt/c/temp/helloworld/helloworld/build'
    [100%] Built target helloworld
    make[1]: Leaving directory '/mnt/c/temp/helloworld/helloworld/build'
    /usr/local/bin/cmake -E cmake_progress_start /mnt/c/temp/helloworld/helloworld/build/CMakeFiles 0
    

    You can see that cmake runs cppcheck with same input as gcc with something called "cmake -E __run_co_compile --cppcheck"

    /usr/local/bin/cmake -E __run_co_compile --cppcheck=/usr/bin/cppcheck --source=/mnt/c/temp/helloworld/helloworld/1.c -- /usr/bin/cc    -MD -MT CMakeFiles/helloworld.dir/1.c.o -MF CMakeFiles/helloworld.dir/1.c.o.d -o CMakeFiles/helloworld.dir/1.c.o -c /mnt/c/temp/helloworld/helloworld/1.c
    Checking /mnt/c/temp/helloworld/helloworld/1.c ...
    

    If then modify 1.c with something that clearly generates a warning like adding unused function and clean rebuild, the warnings are output.

    cmake ..
    cmake --build . --clean-first
    

    One detail I´m not sure if it matters is that we are using Ninja instead Make, for the cmake build.

     
  • Daniel Marjamäki

    ok I can reproduce similar output as you get in your last comment.

    I see no FileNotFoundError when I run with --addon=misra. It's not too easy to reproduce.

    You obviously have some other CPPCHECK_ARGS_DEFAULT arguments.

    Did you try to repeat those arguments exactly on the command line? And then it does not crash? But if you run cmake --build . -v it crashes?

     

Log in to post a comment.