From e69c26a0cedc8b539604b050363e47ad7ae974ba Mon Sep 17 00:00:00 2001 From: Tim Gerundt Date: Fri, 1 Jul 2011 17:06:56 +0200 Subject: [PATCH] Manual: Use and tags --- man/manual.docbook | 52 ++++++++++++++++++++----------------- man/writing-rules-1.docbook | 4 +-- man/writing-rules-2.docbook | 28 +++++++++++--------- man/writing-rules-3.docbook | 2 +- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/man/manual.docbook b/man/manual.docbook index ac5b93e75..ce9da73dd 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -109,8 +109,8 @@ Checking path/file2.cpp... All files under src/a and src/b are then checked. - The second option is to use -i, with it you - specify files/paths to ignore. With this command no files in + The second option is to use -i, + with it you specify files/paths to ignore. With this command no files in src/c are checked: cppcheck -isrc/c src @@ -175,16 +175,17 @@ Checking path/file2.cpp...
Enable messages - By default only error messages are shown. - Through the --enable command more checks can be - enabled. + By default only error messages + are shown. Through the --enable + command more checks can be enabled.
Stylistic issues - With --enable=style you enable most - warning, style and - performance messages. + With --enable=style you + enable most warning, + style and + performance messages. Here is a simple code example: @@ -198,8 +199,8 @@ Checking path/file2.cpp... } There are no bugs in that code so Cppcheck won't report anything - by default. To enable the stylistic messages, use the --enable=style - command: + by default. To enable the stylistic messages, use the + --enable=style command: cppcheck --enable=style file3.c @@ -224,7 +225,7 @@ Checking path/file2.cpp... Enable all checks To enable all checks your can use the - --enable=all flag: + --enable=all flag: cppcheck --enable=all path
@@ -257,7 +258,7 @@ Checking path/file2.cpp... behaviour. But if you want to manually limit the checking you can do so with - -D. + -D. Beware that only the macros, which are given here and the macros defined in source files and known header files are considered. That @@ -276,7 +277,8 @@ Checking path/file2.cpp... Cppcheck can generate the output in XML format. - Use the --xml flag when you execute cppcheck: + Use the --xml flag when you + execute cppcheck: cppcheck --xml file1.cpp @@ -341,8 +343,8 @@ Checking path/file2.cpp... If you want to reformat the output so it looks different you can use templates. - To get Visual Studio compatible output you can use "--template - vs": + To get Visual Studio compatible output you can use + --template vs: cppcheck --template vs gui/test.cpp @@ -352,7 +354,8 @@ Checking path/file2.cpp... gui/test.cpp(31): error: Memory leak: b gui/test.cpp(16): error: Mismatching allocation and deallocation: k - To get gcc compatible output you can use "--template gcc": + To get gcc compatible output you can use + --template gcc: cppcheck --template gcc gui/test.cpp @@ -380,16 +383,17 @@ gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocati Suppressions If you want to filter out certain errors you can suppress these. - The --suppress= command line option is used to specify - suppressions on the command line. The format is one of: + The --suppress= command line option + is used to specify suppressions on the command line. + The format is one of: [error id]:[filename]:[line] [error id]:[filename2] [error id] The error id is the id that you want to suppress. - The easiest way to get it is to use the --xml command - line flag. Copy and paste the id string from the XML + The easiest way to get it is to use the --xml + command line flag. Copy and paste the id string from the XML output. This may be * to suppress all warnings (for a specified file or files). @@ -425,7 +429,7 @@ uninitvar
User-defined allocation/deallocation functions - Cppcheck understands many common allocation and + Cppcheck understands many common allocation and deallocation functions. But not all. Here is example code that might leak memory or resources: @@ -459,11 +463,11 @@ void DestroyFred(void *p) When Cppcheck see this it understands that CreateFred will return allocated memory and that DestroyFred will deallocate memory. - Now, execute Cppcheck this way: + Now, execute cppcheck this way: cppcheck --append=fred.cpp fred1.cpp - The output from cppcheck is: + The output from cppcheck is: Checking fred1.cpp... [fred1.cpp:5]: (error) Memory leak: f @@ -487,7 +491,7 @@ void DestroyFred(void *p) code. To enable the exception safety checking you can use - --enable: + --enable: cppcheck --enable=exceptNew --enable=exceptRealloc fred.cpp diff --git a/man/writing-rules-1.docbook b/man/writing-rules-1.docbook index 45dabd74a..0de22f83d 100644 --- a/man/writing-rules-1.docbook +++ b/man/writing-rules-1.docbook @@ -30,7 +30,7 @@ Data representation of the source code The data used by the rules are not the raw source code. - Cppcheck will read the source code and process it + Cppcheck will read the source code and process it before the rules are used. Cppcheck is designed to find bugs and dangerous code. Stylistic @@ -86,7 +86,7 @@ } Save that code as dealloc.cpp and then use - cppcheck --rule=".+" dealloc.cpp: + cppcheck --rule=".+" dealloc.cpp: $ ./cppcheck --rule=".+" dealloc.cpp Checking dealloc.cpp... diff --git a/man/writing-rules-2.docbook b/man/writing-rules-2.docbook index 4b4295c4e..27f97c380 100644 --- a/man/writing-rules-2.docbook +++ b/man/writing-rules-2.docbook @@ -33,23 +33,25 @@ There are two ways to look at the data representation at runtime. - Using --rule=.+ is one way. All tokens are written on a line: + Using --rule=.+ is one way. + All tokens are written on a line: int a ; int b ; - Using --debug is another way. The tokens are line separated in the - same way as the original code: + Using --debug is another way. + The tokens are line separated in the same way as the original code: 1: int a@1 ; 2: int b@2 ; - In the --debug output there are "@1" and "@2" shown. These are the + In the --debug output there are + "@1" and "@2" shown. These are the variable ids (Cppcheck gives each variable a unique id). You can ignore these if you only plan to write rules with regular expressions, you can't use variable ids with regular expressions. - In general, I will use the --rule=.+ output in - this article because it is more compact. + In general, I will use the --rule=.+ + output in this article because it is more compact.
@@ -130,7 +132,8 @@ s8 x; array[x + 2] = 0; } - The --debug output for that is: + The --debug output for that + is: 1: void f ( ) 2: { @@ -154,7 +157,8 @@ s8 x; free(b); } - The --debug output for that is: + The --debug output for that + is: 1: void f ( ) 2: { @@ -196,7 +200,7 @@ s8 x; f2(); } - The --debug output: + The --debug output: 1: void f ( int x@1 ) 2: { @@ -253,7 +257,7 @@ s8 x; } The x=f1() is broken out. The - --debug output: + --debug output: 1: void f ( ) 2: { @@ -274,7 +278,7 @@ s8 x; } The x=f1() is broken out twice. The - --debug output: + --debug output: 1: void f ( ) 2: { @@ -331,7 +335,7 @@ s8 x; if (x != 0); } - The --debug output is: + The --debug output is: 1: void f ( ) 2: { diff --git a/man/writing-rules-3.docbook b/man/writing-rules-3.docbook index 102937ffe..38869c504 100644 --- a/man/writing-rules-3.docbook +++ b/man/writing-rules-3.docbook @@ -18,7 +18,7 @@ Introduction The goal for this article is to introduce how - Cppcheck rules are written with C++. With C++ it is + Cppcheck rules are written with C++. With C++ it is possible to write more complex rules than is possible with regular expressions.