forked from khiguera/cppcheckTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample4.cpp
More file actions
executable file
·20 lines (15 loc) · 1004 Bytes
/
example4.cpp
File metadata and controls
executable file
·20 lines (15 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*One way to prevent a certain error is by using inline suppression. By
following the format of `// cppcheck-suppress <ERROR:ID>`, cppcheck will
recognize this, and will not print out the error. To turn on inline
suppression, run the command `cppcheck --inline-suppr <FILENAME>`
One can also suppress the error in the command line in the format of
`cppcheck --suppress=<ERROR:ID> <FILENAME>`*/
/*If you don't know what the error is called when you want to suppress it, you can run the command `cppcheck --xml <FILENAME>` Look for "error id = <ERROR>" for the id of the error. Following the same format as the example, you can suppressthat specific error.*/
int foo()
{
char arr[10];
// cppcheck-suppress arrayIndexOutOfBounds
arr[15] = 1;
}
###Why?
This allows you to focus on targeted errors that you are looking for. Perhaps you already know the error is there, but because you will use it, there is no need to fix the error. It will also help keep the noise down when debugging the code.