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><programlisting>void foo(int x)
|
||||
<programlisting>void foo(int x)
|
||||
{
|
||||
void *f = CreateFred();
|
||||
if (x == 1)
|
||||
return;
|
||||
DestroyFred(f);
|
||||
}</programlisting></para>
|
||||
}</programlisting>
|
||||
|
||||
<para>If you analyse that with Cppcheck it won't find any leaks:</para>
|
||||
|
||||
|
@ -460,8 +460,9 @@ void DestroyFred(void *p)
|
|||
free(p);
|
||||
}</programlisting>
|
||||
|
||||
<para>When Cppcheck see this it understands that CreateFred will return
|
||||
allocated memory and that DestroyFred will deallocate memory.</para>
|
||||
<para>When Cppcheck see this it understands that <function>CreateFred()
|
||||
</function> will return allocated memory and that <function>DestroyFred()
|
||||
</function> will deallocate memory.</para>
|
||||
|
||||
<para>Now, execute <command>cppcheck</command> this way:</para>
|
||||
|
||||
|
@ -487,7 +488,7 @@ void DestroyFred(void *p)
|
|||
{
|
||||
}</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>
|
||||
|
||||
<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>
|
||||
|
||||
<para>If an exception occurs when <literal>b</literal> is allocated,
|
||||
<literal>a</literal> will leak.</para>
|
||||
<para>If an exception occurs when <varname>b</varname> is allocated,
|
||||
<varname>a</varname> will leak.</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.
|
||||
You'll need Python and the pygments module
|
||||
(<uri>http://pygments.org/</uri>) 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.</para>
|
||||
(<ulink url="http://pygments.org/">http://pygments.org/</ulink>) for this to
|
||||
work. In the Cppcheck source tree there is a folder
|
||||
<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><programlisting>htmlreport/cppcheck-htmlreport -h</programlisting></para>
|
||||
<programlisting>htmlreport/cppcheck-htmlreport -h</programlisting>
|
||||
|
||||
<para>The output screen says:</para>
|
||||
|
||||
<para><programlisting>Usage: cppcheck-htmlreport [options]
|
||||
<programlisting>Usage: cppcheck-htmlreport [options]
|
||||
|
||||
Options:
|
||||
-h, --help show this help message and exit
|
||||
|
@ -547,7 +549,7 @@ Options:
|
|||
--report-dir=REPORT_DIR
|
||||
The directory where the html report content is written.
|
||||
--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>
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
you write rules.</para>
|
||||
|
||||
<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>
|
||||
</section>
|
||||
|
@ -62,10 +63,10 @@
|
|||
<section>
|
||||
<title>Step 1 - Creating the regular expression</title>
|
||||
|
||||
<para>Cppcheck uses the <literal>PCRE</literal> library to handle
|
||||
regular expressions. <literal>PCRE</literal> stands for "Perl Compatible
|
||||
Regular Expressions". The homepage for <literal>PCRE</literal> is
|
||||
<literal>http://www.pcre.org</literal>.</para>
|
||||
<para>Cppcheck uses the PCRE library to handle regular expressions.
|
||||
<acronym>PCRE</acronym> stands for "Perl Compatible Regular Expressions".
|
||||
The homepage for PCRE is <ulink url="http://www.pcre.org/">
|
||||
http://www.pcre.org/</ulink>.</para>
|
||||
|
||||
<para>Let's create a regular expression that checks for code such
|
||||
as:</para>
|
||||
|
@ -74,7 +75,8 @@
|
|||
free(p);</programlisting>
|
||||
|
||||
<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
|
||||
see what the simplified code looks like you can create a source file
|
||||
|
|
|
@ -256,7 +256,7 @@ s8 x;</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>
|
||||
|
||||
<programlisting>1: void f ( )
|
||||
|
|
Loading…
Reference in New Issue