manual: refactorings
This commit is contained in:
parent
40f2265abf
commit
7126524afc
|
@ -5,14 +5,14 @@
|
||||||
<bookinfo>
|
<bookinfo>
|
||||||
<title>Cppcheck</title>
|
<title>Cppcheck</title>
|
||||||
|
|
||||||
<date>2009-11-14</date>
|
<date>2009-11-16</date>
|
||||||
</bookinfo>
|
</bookinfo>
|
||||||
|
|
||||||
<chapter>
|
<chapter>
|
||||||
<title>Introduction</title>
|
<title>Introduction</title>
|
||||||
|
|
||||||
<para>Cppcheck is an analysis tool for C/C++ code. Unlike C/C++ compilers
|
<para>Cppcheck is an analysis tool for C/C++ code. Unlike C/C++ compilers
|
||||||
and many other analysis tools, we don't detect syntax errors. Cppcheck
|
and many other analysis tools, it doesn't detect syntax errors. Cppcheck
|
||||||
only detects the types of bugs that the compilers normally fail to detect.
|
only detects the types of bugs that the compilers normally fail to detect.
|
||||||
The goal is no false positives.</para>
|
The goal is no false positives.</para>
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Cppcheck is supposed to be compilable by any C++ compiler which
|
<para>Cppcheck is supposed to be compilable by any C++ compiler that
|
||||||
handles the latest C++ standard.</para>
|
handles the latest C++ standard.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
|
@ -84,12 +84,8 @@ Checking path/file2.cpp...
|
||||||
|
|
||||||
<para>By default, an error is only reported when
|
<para>By default, an error is only reported when
|
||||||
<literal><literal>Cppcheck</literal></literal> is sure there is an
|
<literal><literal>Cppcheck</literal></literal> is sure there is an
|
||||||
error.</para>
|
error. When <literal>--all</literal> is given issues will also be
|
||||||
|
reported when <literal>Cppcheck</literal> is unsure.</para>
|
||||||
<para>When a likely issue is discovered <literal>Cppcheck</literal>
|
|
||||||
bails out without reporting this issue - to prevent false positives.
|
|
||||||
When <literal>--all</literal> is given, these issues are
|
|
||||||
reported.</para>
|
|
||||||
|
|
||||||
<para>The <literal>--all</literal> flag is useful but makes
|
<para>The <literal>--all</literal> flag is useful but makes
|
||||||
<literal>Cppcheck</literal> more unreliable, you will probably get false
|
<literal>Cppcheck</literal> more unreliable, you will probably get false
|
||||||
|
@ -143,9 +139,8 @@ Checking path/file2.cpp...
|
||||||
<section>
|
<section>
|
||||||
<title>Saving results in file</title>
|
<title>Saving results in file</title>
|
||||||
|
|
||||||
<para>Many times you will want to save the results in a file. The
|
<para>Many times you will want to save the results in a file. You can
|
||||||
results are written to stderr and the progress messages are written to
|
use the normal shell redirection for piping error output to a
|
||||||
stdout. So you can use the normal shell redirections to save to
|
|
||||||
file.</para>
|
file.</para>
|
||||||
|
|
||||||
<programlisting>cppcheck file1.c 2> err.txt</programlisting>
|
<programlisting>cppcheck file1.c 2> err.txt</programlisting>
|
||||||
|
@ -164,9 +159,7 @@ Checking path/file2.cpp...
|
||||||
<section>
|
<section>
|
||||||
<title>Multithreaded checking</title>
|
<title>Multithreaded checking</title>
|
||||||
|
|
||||||
<para>If you have a multicore processor, it is a good idea to use the
|
<para>To use 4 threads to check the files in a folder:</para>
|
||||||
<literal>-j</literal> flag. To use 4 threads to check the files in a
|
|
||||||
folder:</para>
|
|
||||||
|
|
||||||
<programlisting>cppcheck -j 4 path</programlisting>
|
<programlisting>cppcheck -j 4 path</programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
@ -185,7 +178,8 @@ Checking path/file2.cpp...
|
||||||
|
|
||||||
<programlisting><?xml version="1.0"?>
|
<programlisting><?xml version="1.0"?>
|
||||||
<results>
|
<results>
|
||||||
<error file="file1.cpp" line="123" id="someError" severity="error" msg="some error text"/>
|
<error file="file1.cpp" line="123" id="someError"
|
||||||
|
severity="error" msg="some error text"/>
|
||||||
</results></programlisting>
|
</results></programlisting>
|
||||||
|
|
||||||
<para>Attributes:</para>
|
<para>Attributes:</para>
|
||||||
|
@ -278,7 +272,7 @@ 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.
|
||||||
First you need to create a suppressions file.</para>
|
First you need to create a suppressions file. The format is:</para>
|
||||||
|
|
||||||
<programlisting>[error id]:[filename]
|
<programlisting>[error id]:[filename]
|
||||||
[error id]:[filename2]
|
[error id]:[filename2]
|
||||||
|
@ -344,7 +338,7 @@ QPushButton</programlisting>
|
||||||
<para>Then execute cppcheck with the <literal>--auto-dealloc</literal>
|
<para>Then execute cppcheck with the <literal>--auto-dealloc</literal>
|
||||||
option:</para>
|
option:</para>
|
||||||
|
|
||||||
<programlisting>cppcheck --auto-dealloc qt.lst file1.cpp</programlisting>
|
<programlisting>cppcheck --auto-dealloc qt.lst --all file1.cpp</programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
@ -399,7 +393,7 @@ void DestroyFred(void *p)
|
||||||
<title>Exception safety</title>
|
<title>Exception safety</title>
|
||||||
|
|
||||||
<para>Cppcheck has a few checks that ensure that you don't break the basic
|
<para>Cppcheck has a few checks that ensure that you don't break the basic
|
||||||
guarantee of exception safety. We don't have any checks for the strong
|
guarantee of exception safety. It doesn't have any checks for the strong
|
||||||
guarantee yet.</para>
|
guarantee yet.</para>
|
||||||
|
|
||||||
<para>Example:</para>
|
<para>Example:</para>
|
||||||
|
@ -441,6 +435,7 @@ int a(int sz)
|
||||||
|
|
||||||
<para>The output from Cppcheck is:</para>
|
<para>The output from Cppcheck is:</para>
|
||||||
|
|
||||||
<programlisting>[except2.cpp:7]: (error) Throwing exception in invalid state, p points at deallocated memory</programlisting>
|
<programlisting>[except2.cpp:7]: (error) Throwing exception in invalid state, p points
|
||||||
|
at deallocated memory</programlisting>
|
||||||
</chapter>
|
</chapter>
|
||||||
</book>
|
</book>
|
||||||
|
|
Loading…
Reference in New Issue