How to use cppcheck's inline suppression filter option for C++ code?

29,407

Solution 1

You can change the output template to display the error id from the command line, which is quite neat.

For a Visual Studio format output with error id displayed, add this to your command line:

--template "{file}({line}): {severity} ({id}): {message}"

This will produce output something like this:

s:\src\jpeg.cpp(123): error (bufferAccessOutOfBounds): Buffer access out-of-bounds: abRY

Which you can then suppress by adding the line:

// cppcheck-suppress bufferAccessOutOfBounds

To the previous line in the source file.

Solution 2

According to the cppcheck man page, you can use the --template option to change the default output to include the id, e.g.

cppcheck /the/src/file --template='{file}:{line},{severity},{id},{message}'
Share:
29,407
Blaise
Author by

Blaise

Updated on October 05, 2020

Comments

  • Blaise
    Blaise over 3 years

    I would like to use Cppcheck for static code analysis of my C++ code. I learned that I can suppress some kind of warnings with --inline-suppr command. However, I can't find what "suppressed_error_id" I should put in the comment:

    // cppcheck-suppress "suppressed_error_id"
    
  • Blaise
    Blaise over 7 years
    Hi, can you describe in more detail what GUI you are referring to?
  • crizCraig
    crizCraig over 4 years
    You can use the same template to get a list of possible error id's: cppcheck --errorlist --template='{file}:{line},{severity},{id},{message}'
  • skelliam
    skelliam over 2 years
    @Blaise, Sara is referring to the cppcheck GUI interface.