Manual: Miscellaneous tag changes
This commit is contained in:
parent
533426d3c2
commit
364900c5c0
|
@ -434,13 +434,13 @@ uninitvar</programlisting>
|
||||||
|
|
||||||
<para>Here is example code that might leak memory or resources:</para>
|
<para>Here is example code that might leak memory or resources:</para>
|
||||||
|
|
||||||
<para><programlisting>void foo(int x)
|
<programlisting>void foo(int x)
|
||||||
{
|
{
|
||||||
void *f = CreateFred();
|
void *f = CreateFred();
|
||||||
if (x == 1)
|
if (x == 1)
|
||||||
return;
|
return;
|
||||||
DestroyFred(f);
|
DestroyFred(f);
|
||||||
}</programlisting></para>
|
}</programlisting>
|
||||||
|
|
||||||
<para>If you analyse that with Cppcheck it won't find any leaks:</para>
|
<para>If you analyse that with Cppcheck it won't find any leaks:</para>
|
||||||
|
|
||||||
|
@ -460,8 +460,9 @@ void DestroyFred(void *p)
|
||||||
free(p);
|
free(p);
|
||||||
}</programlisting>
|
}</programlisting>
|
||||||
|
|
||||||
<para>When Cppcheck see this it understands that CreateFred will return
|
<para>When Cppcheck see this it understands that <function>CreateFred()
|
||||||
allocated memory and that DestroyFred will deallocate memory.</para>
|
</function> will return allocated memory and that <function>DestroyFred()
|
||||||
|
</function> will deallocate memory.</para>
|
||||||
|
|
||||||
<para>Now, execute <command>cppcheck</command> this way:</para>
|
<para>Now, execute <command>cppcheck</command> this way:</para>
|
||||||
|
|
||||||
|
@ -487,7 +488,7 @@ void DestroyFred(void *p)
|
||||||
{
|
{
|
||||||
}</programlisting>
|
}</programlisting>
|
||||||
|
|
||||||
<para>By default cppcheck will not detect any problems in that
|
<para>By default Cppcheck will not detect any problems in that
|
||||||
code.</para>
|
code.</para>
|
||||||
|
|
||||||
<para>To enable the exception safety checking you can use
|
<para>To enable the exception safety checking you can use
|
||||||
|
@ -499,8 +500,8 @@ void DestroyFred(void *p)
|
||||||
|
|
||||||
<programlisting>[fred.cpp:3]: (style) Upon exception there is memory leak: a</programlisting>
|
<programlisting>[fred.cpp:3]: (style) Upon exception there is memory leak: a</programlisting>
|
||||||
|
|
||||||
<para>If an exception occurs when <literal>b</literal> is allocated,
|
<para>If an exception occurs when <varname>b</varname> is allocated,
|
||||||
<literal>a</literal> will leak.</para>
|
<varname>a</varname> will leak.</para>
|
||||||
|
|
||||||
<para>Here is another example:</para>
|
<para>Here is another example:</para>
|
||||||
|
|
||||||
|
@ -528,17 +529,18 @@ int a(int sz)
|
||||||
|
|
||||||
<para>You can convert the XML output from cppcheck into a HTML report.
|
<para>You can convert the XML output from cppcheck into a HTML report.
|
||||||
You'll need Python and the pygments module
|
You'll need Python and the pygments module
|
||||||
(<uri>http://pygments.org/</uri>) for this to work. In the Cppcheck source
|
(<ulink url="http://pygments.org/">http://pygments.org/</ulink>) for this to
|
||||||
tree there is a folder "htmlreport" that contains a script that transforms
|
work. In the Cppcheck source tree there is a folder
|
||||||
a Cppcheck XML file into HTML output.</para>
|
<filename class="directory">htmlreport</filename> that contains a script
|
||||||
|
that transforms a Cppcheck XML file into HTML output.</para>
|
||||||
|
|
||||||
<para>This command generates the help screen:</para>
|
<para>This command generates the help screen:</para>
|
||||||
|
|
||||||
<para><programlisting>htmlreport/cppcheck-htmlreport -h</programlisting></para>
|
<programlisting>htmlreport/cppcheck-htmlreport -h</programlisting>
|
||||||
|
|
||||||
<para>The output screen says:</para>
|
<para>The output screen says:</para>
|
||||||
|
|
||||||
<para><programlisting>Usage: cppcheck-htmlreport [options]
|
<programlisting>Usage: cppcheck-htmlreport [options]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
@ -547,7 +549,7 @@ Options:
|
||||||
--report-dir=REPORT_DIR
|
--report-dir=REPORT_DIR
|
||||||
The directory where the html report content is written.
|
The directory where the html report content is written.
|
||||||
--source-dir=SOURCE_DIR
|
--source-dir=SOURCE_DIR
|
||||||
Base directory where source code files can be found.</programlisting></para>
|
Base directory where source code files can be found.</programlisting>
|
||||||
|
|
||||||
<para>An example usage:</para>
|
<para>An example usage:</para>
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@
|
||||||
you write rules.</para>
|
you write rules.</para>
|
||||||
|
|
||||||
<para>Between each token in the code there is always a space. For instance
|
<para>Between each token in the code there is always a space. For instance
|
||||||
the raw code "1+f()" is processed into "1 + f ( )".</para>
|
the raw code "<code>1+f()</code>" is processed into "<code>1 + f ( )</code>"
|
||||||
|
.</para>
|
||||||
|
|
||||||
<para>The code is simplified in many ways.</para>
|
<para>The code is simplified in many ways.</para>
|
||||||
</section>
|
</section>
|
||||||
|
@ -62,10 +63,10 @@
|
||||||
<section>
|
<section>
|
||||||
<title>Step 1 - Creating the regular expression</title>
|
<title>Step 1 - Creating the regular expression</title>
|
||||||
|
|
||||||
<para>Cppcheck uses the <literal>PCRE</literal> library to handle
|
<para>Cppcheck uses the PCRE library to handle regular expressions.
|
||||||
regular expressions. <literal>PCRE</literal> stands for "Perl Compatible
|
<acronym>PCRE</acronym> stands for "Perl Compatible Regular Expressions".
|
||||||
Regular Expressions". The homepage for <literal>PCRE</literal> is
|
The homepage for PCRE is <ulink url="http://www.pcre.org/">
|
||||||
<literal>http://www.pcre.org</literal>.</para>
|
http://www.pcre.org/</ulink>.</para>
|
||||||
|
|
||||||
<para>Let's create a regular expression that checks for code such
|
<para>Let's create a regular expression that checks for code such
|
||||||
as:</para>
|
as:</para>
|
||||||
|
@ -74,7 +75,8 @@
|
||||||
free(p);</programlisting>
|
free(p);</programlisting>
|
||||||
|
|
||||||
<para>For such code the condition is often redundant (on most
|
<para>For such code the condition is often redundant (on most
|
||||||
implementations it is valid to free a NULL pointer).</para>
|
implementations it is valid to free a <constant>NULL</constant> pointer).
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>The regular expression must be written for the simplified code. To
|
<para>The regular expression must be written for the simplified code. To
|
||||||
see what the simplified code looks like you can create a source file
|
see what the simplified code looks like you can create a source file
|
||||||
|
|
|
@ -256,7 +256,7 @@ s8 x;</programlisting>
|
||||||
}
|
}
|
||||||
}</programlisting>
|
}</programlisting>
|
||||||
|
|
||||||
<para>The <literal>x=f1()</literal> is broken out. The
|
<para>The <code>x=f1()</code> is broken out. The
|
||||||
<parameter class="command">--debug</parameter> output:</para>
|
<parameter class="command">--debug</parameter> output:</para>
|
||||||
|
|
||||||
<programlisting>1: void f ( )
|
<programlisting>1: void f ( )
|
||||||
|
|
Loading…
Reference in New Issue