You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: man/manual.md
+20-33Lines changed: 20 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,4 @@
1
1
2
-
3
2
# Cppcheck 1.88 dev
4
3
5
4
## Introduction
@@ -8,9 +7,9 @@ Cppcheck is an analysis tool for C/C++ code. It provides unique code analysis to
8
7
9
8
Supported code and platforms:
10
9
11
-
- You can check non-standard code that contains various compiler extensions, inline assembly code, etc.
12
-
- Cppcheck should be compilable by any C++ compiler that handles the latest C++ standard.
13
-
- Cppcheck should work on any platform that has sufficient CPU and memory.
10
+
- You can check non-standard code that contains various compiler extensions, inline assembly code, etc.
11
+
- Cppcheck should be compilable by any C++ compiler that handles the latest C++ standard.
12
+
- Cppcheck should work on any platform that has sufficient CPU and memory.
14
13
15
14
Please understand that there are limits of Cppcheck. Cppcheck is rarely wrong about reported errors. But there are
16
15
many bugs that it doesn't detect.
@@ -28,9 +27,10 @@ good results.
28
27
29
28
In the project settings dialog, the first option you see is "Import project". It is recommended that you use this
30
29
feature if you can. Cppcheck can import:
31
-
- Visual studio solution / project
32
-
- Compile database (can be generated from cmake/qbs/etc build files)
33
-
- Borland C++ Builder 6
30
+
31
+
- Visual studio solution / project
32
+
- Compile database (can be generated from cmake/qbs/etc build files)
33
+
- Borland C++ Builder 6
34
34
35
35
When you have filled out the project settings and click on OK; the Cppcheck analysis will start.
36
36
@@ -56,7 +56,6 @@ The output from cppcheck will then be:
56
56
Checking file1.c...
57
57
[file1.c:4]: (error) Array 'a[10]' index 10 out of bounds
58
58
59
-
60
59
#### Checking all files in a folder
61
60
62
61
Normally a program has many source files. And you want to check them all. Cppcheck can check all source files in a directory:
@@ -122,7 +121,6 @@ portability warnings. 64-bit portability. code might work different on different
122
121
123
122
Configuration problems. The recommendation is to only enable these during configuration.
124
123
125
-
126
124
## Importing project
127
125
128
126
You can import some project files and build configurations into Cppcheck.
@@ -197,7 +195,6 @@ You can also create your own custom platform configuration in a xml file. Here i
197
195
</sizeof>
198
196
</platform>
199
197
200
-
201
198
## Preprocessor Settings
202
199
203
200
If you use `--project` then Cppcheck will use the preprocessor settings from the imported project. Otherwise you'll probably want to configure the include paths, defines, etc.
@@ -212,7 +209,7 @@ Here is a file that has 2 preprocessor configurations (with A defined and withou
212
209
x = z;
213
210
#endif
214
211
215
-
By default Cppcheck will check all preprocessor configurations (except those that have #error in them). So the above code will by default be analyzed both with `A` defined and without `A` defined.
212
+
By default Cppcheck will check all preprocessor configurations (except those that have #error in them). So the above code will by default be analyzed both with `A` defined and without `A` defined.
216
213
217
214
You can use `-D` to change this. When you use `-D`, cppcheck will by default only check the given configuration and nothing else. This is how compilers work. But you can use `--force` or `--max-configs` to override the number of configurations.
218
215
@@ -234,7 +231,6 @@ Another useful flag might be `-U`. It tells Cppcheck that a macro is not defined
234
231
235
232
That will mean that X is not defined. Cppcheck will not check what happens when X is defined.
236
233
237
-
238
234
### Include paths
239
235
240
236
To add an include path, use `-I`, followed by the path.
@@ -247,7 +243,7 @@ The purpose of this behaviour is that cppcheck is meant to work without necessar
247
243
248
244
If you want to filter out certain errors you can suppress these.
249
245
250
-
Please note that if you see a false positive then we (the Cppcheck team) want that you report it so we can fix it.
246
+
Please note that if you see a false positive then we (the Cppcheck team) want that you report it so we can fix it.
251
247
252
248
### Plain text suppressions
253
249
@@ -267,15 +263,14 @@ The `--suppress=` command line option is used to specify suppressions on the com
267
263
268
264
cppcheck --suppress=memleak:src/file1.cpp src/
269
265
270
-
271
266
### Suppressions in a file
272
267
273
268
You can create a suppressions file. Example:
274
269
275
270
// suppress memleak and exceptNew errors in the file src/file1.cpp
276
271
memleak:src/file1.cpp
277
272
exceptNew:src/file1.cpp
278
-
273
+
279
274
// suppress all uninitvar errors in all files
280
275
uninitvar
281
276
@@ -325,7 +320,7 @@ To suppress the error message, a comment can be added:
325
320
326
321
void f() {
327
322
char arr[5];
328
-
323
+
329
324
// cppcheck-suppress arrayIndexOutOfBounds
330
325
arr[10] = 0;
331
326
}
@@ -343,7 +338,6 @@ You can write comments for the suppress, however is recommended to use ; or // t
343
338
// cppcheck-suppress arrayIndexOutOfBounds ; some comment
344
339
// cppcheck-suppress arrayIndexOutOfBounds // some comment
345
340
346
-
347
341
## XML output
348
342
349
343
Cppcheck can generate output in XML format. Use `--xml` to enable this format.
@@ -469,7 +463,7 @@ Many warnings have multiple locations. Example code:
469
463
{
470
464
*p = 3; // line 3
471
465
}
472
-
466
+
473
467
int main()
474
468
{
475
469
int *p = 0; // line 8
@@ -503,7 +497,6 @@ The first line in the warning is formatted by the --template format.
503
497
504
498
The other lines in the warning are formatted by the --template-location format.
505
499
506
-
507
500
#### Format specifiers for --template
508
501
509
502
The available specifiers for --template are:
@@ -556,7 +549,6 @@ Newline
556
549
557
550
Carriage return
558
551
559
-
560
552
#### Format specifiers for --template-location
561
553
562
554
The available specifiers for `--template-location` are:
@@ -614,9 +606,10 @@ Imagine this source code:
614
606
}
615
607
616
608
By default Cppcheck will try to check all the configurations. There are 3 important configurations here:
617
-
* Neither `__GNUC__` nor `_MSC_VER` is defined
618
-
*`__GNUC__` is defined
619
-
*`_MSC_VER` is defined
609
+
610
+
- Neither `__GNUC__` nor `_MSC_VER` is defined
611
+
-`__GNUC__` is defined
612
+
-`_MSC_VER` is defined
620
613
621
614
When you run Cppcheck, the output will be something like:
622
615
@@ -632,7 +625,6 @@ Now if you want you can limit the analysis. You probably know what the target co
632
625
Checking test.c ...
633
626
Checking test.c: __GNUC__=1...
634
627
635
-
636
628
### Unused templates
637
629
638
630
If you think Cppcheck is slow and you are using templates, then you should try how it works to remove unused templates.
@@ -685,7 +677,7 @@ You need:
685
677
686
678
Python 2.X or 3.X
687
679
688
-
The MISRA C 2012 PDF. You can buy this from http://www.misra.org.uk (costs 15-20 pounds)
680
+
The MISRA C 2012 PDF. You can buy this from <http://www.misra.org.uk> (costs 15-20 pounds)
689
681
690
682
#### MISRA Text file
691
683
@@ -710,7 +702,6 @@ To create the text file manually, copy paste Appendix A "Summary of guidelines"
710
702
711
703
Rules that you want to disable does not need to have a rule text. Rules that don't have rule text will be suppressed by the addon.
712
704
713
-
714
705
## Library configuration
715
706
716
707
When external libraries are used, such as WinAPI, POSIX, gtk, Qt, etc, Cppcheck doesn't know how the external functions behave. Cppcheck then fails to detect various problems such as leaks, buffer overflows, possible null pointer dereferences, etc. But this can be fixed with configuration files.
@@ -988,8 +979,7 @@ Some example expressions you can use in the valid element:
988
979
:0 => all values that are less or equal to 0 are valid
989
980
0: => all values that are greater or equal to 0 are valid
990
981
0,2:32 => the value 0 and all values between 2 and 32 are valid
991
-
-1.5:5.6 => all values between -1.5 and 5.6 are valid
992
-
982
+
-1.5:5.6 => all values between -1.5 and 5.6 are valid
993
983
994
984
##### `<minsize>`
995
985
@@ -1050,7 +1040,6 @@ With this you can say that an argument must be a zero-terminated string.
1050
1040
</function>
1051
1041
</def>
1052
1042
1053
-
1054
1043
##### `<noreturn>`
1055
1044
1056
1045
Cppcheck doesn't assume that functions always return. Here is an example code:
@@ -1152,7 +1141,7 @@ Cppcheck normally assumes that the result might be different, and reports no war
1152
1141
1153
1142
If a proper const.cfg is provided, the unreachable code is detected:
1154
1143
1155
-
$ cppcheck --enable=style --library=const const.c
1144
+
$ cppcheck --enable=style --library=const const.c
1156
1145
Checking const.c...
1157
1146
[const.c:7]: (style) Expression is always false because 'else if' condition matches previous condition at line 5.
1158
1147
@@ -1253,10 +1242,9 @@ The following example provides a definition for std::vector, based on the defini
1253
1242
</container>
1254
1243
</def>
1255
1244
1256
-
1257
1245
## HTML Report
1258
1246
1259
-
You can convert the XML output from cppcheck into a HTML report. You'll need Python and the pygments module (http://pygments.org/) for this to work. In the Cppcheck source tree there is a folder htmlreport that contains a script that transforms a Cppcheck XML file into HTML output.
1247
+
You can convert the XML output from cppcheck into a HTML report. You'll need Python and the pygments module (<http://pygments.org/)> for this to work. In the Cppcheck source tree there is a folder htmlreport that contains a script that transforms a Cppcheck XML file into HTML output.
0 commit comments