Manual: Use <command> and <parameter> tags

This commit is contained in:
Tim Gerundt 2011-07-01 17:06:56 +02:00
parent 4a25327b57
commit e69c26a0ce
4 changed files with 47 additions and 39 deletions

View File

@ -109,8 +109,8 @@ Checking path/file2.cpp...
<para>All files under <filename class="directory">src/a</filename> and <para>All files under <filename class="directory">src/a</filename> and
<filename class="directory">src/b</filename> are then checked.</para> <filename class="directory">src/b</filename> are then checked.</para>
<para>The second option is to use <literal>-i</literal>, with it you <para>The second option is to use <parameter class="command">-i</parameter>,
specify files/paths to ignore. With this command no files in with it you specify files/paths to ignore. With this command no files in
<filename class="directory">src/c</filename> are checked:</para> <filename class="directory">src/c</filename> are checked:</para>
<programlisting>cppcheck -isrc/c src</programlisting> <programlisting>cppcheck -isrc/c src</programlisting>
@ -175,16 +175,17 @@ Checking path/file2.cpp...
<section> <section>
<title>Enable messages</title> <title>Enable messages</title>
<para>By default only <literal>error</literal> messages are shown. <para>By default only <parameter class="command">error</parameter> messages
Through the <literal>--enable</literal> command more checks can be are shown. Through the <parameter class="command">--enable</parameter>
enabled.</para> command more checks can be enabled.</para>
<section> <section>
<title>Stylistic issues</title> <title>Stylistic issues</title>
<para>With <literal>--enable=style</literal> you enable most <para>With <parameter class="command">--enable=style</parameter> you
<literal>warning</literal>, <literal>style</literal> and enable most <parameter class="command">warning</parameter>,
<literal>performance</literal> messages.</para> <parameter class="command">style</parameter> and
<parameter class="command">performance</parameter> messages.</para>
<para>Here is a simple code example:</para> <para>Here is a simple code example:</para>
@ -198,8 +199,8 @@ Checking path/file2.cpp...
}</programlisting> }</programlisting>
<para>There are no bugs in that code so Cppcheck won't report anything <para>There are no bugs in that code so Cppcheck won't report anything
by default. To enable the stylistic messages, use the --enable=style by default. To enable the stylistic messages, use the
command:</para> <parameter class="command">--enable=style</parameter> command:</para>
<programlisting>cppcheck --enable=style file3.c</programlisting> <programlisting>cppcheck --enable=style file3.c</programlisting>
@ -224,7 +225,7 @@ Checking path/file2.cpp...
<title>Enable all checks</title> <title>Enable all checks</title>
<para>To enable all checks your can use the <para>To enable all checks your can use the
<literal>--enable=all</literal> flag:</para> <parameter class="command">--enable=all</parameter> flag:</para>
<programlisting>cppcheck --enable=all path</programlisting> <programlisting>cppcheck --enable=all path</programlisting>
</section> </section>
@ -257,7 +258,7 @@ Checking path/file2.cpp...
behaviour.</para> behaviour.</para>
<para>But if you want to manually limit the checking you can do so with <para>But if you want to manually limit the checking you can do so with
<literal>-D</literal>.</para> <parameter class="command">-D</parameter>.</para>
<para>Beware that only the macros, which are given here and the macros <para>Beware that only the macros, which are given here and the macros
defined in source files and known header files are considered. That defined in source files and known header files are considered. That
@ -276,7 +277,8 @@ Checking path/file2.cpp...
<para>Cppcheck can generate the output in XML format.</para> <para>Cppcheck can generate the output in XML format.</para>
<para>Use the --xml flag when you execute cppcheck:</para> <para>Use the <parameter class="command">--xml</parameter> flag when you
execute cppcheck:</para>
<programlisting>cppcheck --xml file1.cpp</programlisting> <programlisting>cppcheck --xml file1.cpp</programlisting>
@ -341,8 +343,8 @@ Checking path/file2.cpp...
<para>If you want to reformat the output so it looks different you can use <para>If you want to reformat the output so it looks different you can use
templates.</para> templates.</para>
<para>To get Visual Studio compatible output you can use "--template <para>To get Visual Studio compatible output you can use
vs":</para> <parameter class="command">--template vs</parameter>:</para>
<programlisting>cppcheck --template vs gui/test.cpp</programlisting> <programlisting>cppcheck --template vs gui/test.cpp</programlisting>
@ -352,7 +354,8 @@ Checking path/file2.cpp...
gui/test.cpp(31): error: Memory leak: b gui/test.cpp(31): error: Memory leak: b
gui/test.cpp(16): error: Mismatching allocation and deallocation: k</programlisting> gui/test.cpp(16): error: Mismatching allocation and deallocation: k</programlisting>
<para>To get gcc compatible output you can use "--template gcc":</para> <para>To get gcc compatible output you can use
<parameter class="command">--template gcc</parameter>:</para>
<programlisting>cppcheck --template gcc gui/test.cpp</programlisting> <programlisting>cppcheck --template gcc gui/test.cpp</programlisting>
@ -380,16 +383,17 @@ gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocati
<title>Suppressions</title> <title>Suppressions</title>
<para>If you want to filter out certain errors you can suppress these. <para>If you want to filter out certain errors you can suppress these.
The <literal>--suppress=</literal> command line option is used to specify The <parameter class="command">--suppress=</parameter> command line option
suppressions on the command line. The format is one of:</para> is used to specify suppressions on the command line.
The format is one of:</para>
<programlisting>[error id]:[filename]:[line] <programlisting>[error id]:[filename]:[line]
[error id]:[filename2] [error id]:[filename2]
[error id]</programlisting> [error id]</programlisting>
<para>The <literal>error id</literal> is the id that you want to suppress. <para>The <literal>error id</literal> is the id that you want to suppress.
The easiest way to get it is to use the <literal>--xml</literal> command The easiest way to get it is to use the <parameter class="command">--xml</parameter>
line flag. Copy and paste the <literal>id</literal> string from the XML command line flag. Copy and paste the <literal>id</literal> string from the XML
output. This may be * to suppress all warnings (for a specified file or output. This may be * to suppress all warnings (for a specified file or
files).</para> files).</para>
@ -425,7 +429,7 @@ uninitvar</programlisting>
<section> <section>
<title>User-defined allocation/deallocation functions</title> <title>User-defined allocation/deallocation functions</title>
<para><literal>Cppcheck</literal> understands many common allocation and <para>Cppcheck understands many common allocation and
deallocation functions. But not all.</para> deallocation functions. But not all.</para>
<para>Here is example code that might leak memory or resources:</para> <para>Here is example code that might leak memory or resources:</para>
@ -459,11 +463,11 @@ void DestroyFred(void *p)
<para>When Cppcheck see this it understands that CreateFred will return <para>When Cppcheck see this it understands that CreateFred will return
allocated memory and that DestroyFred will deallocate memory.</para> allocated memory and that DestroyFred will deallocate memory.</para>
<para>Now, execute <literal>Cppcheck</literal> this way:</para> <para>Now, execute <command>cppcheck</command> this way:</para>
<programlisting>cppcheck --append=fred.cpp fred1.cpp</programlisting> <programlisting>cppcheck --append=fred.cpp fred1.cpp</programlisting>
<para>The output from cppcheck is:</para> <para>The output from <command>cppcheck</command> is:</para>
<programlisting>Checking fred1.cpp... <programlisting>Checking fred1.cpp...
[fred1.cpp:5]: (error) Memory leak: f</programlisting> [fred1.cpp:5]: (error) Memory leak: f</programlisting>
@ -487,7 +491,7 @@ void DestroyFred(void *p)
code.</para> code.</para>
<para>To enable the exception safety checking you can use <para>To enable the exception safety checking you can use
<literal>--enable</literal>:</para> <parameter class="command">--enable</parameter>:</para>
<programlisting>cppcheck --enable=exceptNew --enable=exceptRealloc fred.cpp</programlisting> <programlisting>cppcheck --enable=exceptNew --enable=exceptRealloc fred.cpp</programlisting>

View File

@ -30,7 +30,7 @@
<title>Data representation of the source code</title> <title>Data representation of the source code</title>
<para>The data used by the rules are not the raw source code. <para>The data used by the rules are not the raw source code.
<literal>Cppcheck</literal> will read the source code and process it Cppcheck will read the source code and process it
before the rules are used.</para> before the rules are used.</para>
<para>Cppcheck is designed to find bugs and dangerous code. Stylistic <para>Cppcheck is designed to find bugs and dangerous code. Stylistic
@ -86,7 +86,7 @@
}</programlisting> }</programlisting>
<para>Save that code as <filename>dealloc.cpp</filename> and then use <para>Save that code as <filename>dealloc.cpp</filename> and then use
<literal>cppcheck --rule=".+" dealloc.cpp</literal>:</para> <command>cppcheck --rule=".+" dealloc.cpp</command>:</para>
<programlisting>$ ./cppcheck --rule=".+" dealloc.cpp <programlisting>$ ./cppcheck --rule=".+" dealloc.cpp
Checking dealloc.cpp... Checking dealloc.cpp...

View File

@ -33,23 +33,25 @@
<para>There are two ways to look at the data representation at <para>There are two ways to look at the data representation at
runtime.</para> runtime.</para>
<para>Using --rule=.+ is one way. All tokens are written on a line:</para> <para>Using <parameter class="command">--rule=.+</parameter> is one way.
All tokens are written on a line:</para>
<programlisting> int a ; int b ;</programlisting> <programlisting> int a ; int b ;</programlisting>
<para>Using --debug is another way. The tokens are line separated in the <para>Using <parameter class="command">--debug</parameter> is another way.
same way as the original code:</para> The tokens are line separated in the same way as the original code:</para>
<programlisting>1: int a@1 ; <programlisting>1: int a@1 ;
2: int b@2 ;</programlisting> 2: int b@2 ;</programlisting>
<para>In the --debug output there are "@1" and "@2" shown. These are the <para>In the <parameter class="command">--debug</parameter> output there are
"@1" and "@2" shown. These are the
variable ids (Cppcheck gives each variable a unique id). You can ignore 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 these if you only plan to write rules with regular expressions, you can't
use variable ids with regular expressions.</para> use variable ids with regular expressions.</para>
<para>In general, I will use the <literal>--rule=.+</literal> output in <para>In general, I will use the <parameter class="command">--rule=.+</parameter>
this article because it is more compact.</para> output in this article because it is more compact.</para>
</section> </section>
<section> <section>
@ -130,7 +132,8 @@ s8 x;</programlisting>
array[x + 2] = 0; array[x + 2] = 0;
}</programlisting> }</programlisting>
<para>The <literal>--debug</literal> output for that is:</para> <para>The <parameter class="command">--debug</parameter> output for that
is:</para>
<programlisting>1: void f ( ) <programlisting>1: void f ( )
2: { 2: {
@ -154,7 +157,8 @@ s8 x;</programlisting>
free(b); free(b);
}</programlisting> }</programlisting>
<para>The <literal>--debug</literal> output for that is:</para> <para>The <parameter class="command">--debug</parameter> output for that
is:</para>
<programlisting>1: void f ( ) <programlisting>1: void f ( )
2: { 2: {
@ -196,7 +200,7 @@ s8 x;</programlisting>
f2(); f2();
}</programlisting> }</programlisting>
<para>The <literal>--debug</literal> output:</para> <para>The <parameter class="command">--debug</parameter> output:</para>
<programlisting>1: void f ( int x@1 ) <programlisting>1: void f ( int x@1 )
2: { 2: {
@ -253,7 +257,7 @@ s8 x;</programlisting>
}</programlisting> }</programlisting>
<para>The <literal>x=f1()</literal> is broken out. The <para>The <literal>x=f1()</literal> is broken out. The
<literal>--debug</literal> output:</para> <parameter class="command">--debug</parameter> output:</para>
<programlisting>1: void f ( ) <programlisting>1: void f ( )
2: { 2: {
@ -274,7 +278,7 @@ s8 x;</programlisting>
}</programlisting> }</programlisting>
<para>The <literal>x=f1()</literal> is broken out twice. The <para>The <literal>x=f1()</literal> is broken out twice. The
<literal>--debug</literal> output:</para> <parameter class="command">--debug</parameter> output:</para>
<programlisting>1: void f ( ) <programlisting>1: void f ( )
2: { 2: {
@ -331,7 +335,7 @@ s8 x;</programlisting>
if (x != 0); if (x != 0);
}</programlisting> }</programlisting>
<para>The <literal>--debug</literal> output is:</para> <para>The <parameter class="command">--debug</parameter> output is:</para>
<programlisting>1: void f ( ) <programlisting>1: void f ( )
2: { 2: {

View File

@ -18,7 +18,7 @@
<title>Introduction</title> <title>Introduction</title>
<para>The goal for this article is to introduce how <para>The goal for this article is to introduce how
<literal>Cppcheck</literal> 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 possible to write more complex rules than is possible with regular
expressions.</para> expressions.</para>
</section> </section>