Manual: Described file0 attribute in XML output and the relationship between <not-null/> and <not-uninit/>
This commit is contained in:
parent
e2a04c508c
commit
dec839ea79
|
@ -362,7 +362,7 @@ cppcheck -DA --force file.c</programlisting>
|
||||||
<errors>
|
<errors>
|
||||||
<error id="someError" severity="error" msg="short error text"
|
<error id="someError" severity="error" msg="short error text"
|
||||||
verbose="long error text" inconclusive="true" cwe="312">
|
verbose="long error text" inconclusive="true" cwe="312">
|
||||||
<location file="file.c" line="1"/>
|
<location file0="file.c" file="file.h" line="1"/>
|
||||||
</error>
|
</error>
|
||||||
</errors>
|
</errors>
|
||||||
</results></programlisting>
|
</results></programlisting>
|
||||||
|
@ -448,6 +448,14 @@ cppcheck -DA --force file.c</programlisting>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><sgmltag class="attribute">file0</sgmltag></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>name of the source file (optional)</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><sgmltag class="attribute">line</sgmltag></term>
|
<term><sgmltag class="attribute">line</sgmltag></term>
|
||||||
|
|
||||||
|
@ -808,7 +816,7 @@ Checking pen1.c...
|
||||||
<literal>default="value"</literal>. Specifying <literal>-1</literal> as the argument
|
<literal>default="value"</literal>. Specifying <literal>-1</literal> as the argument
|
||||||
number is going to apply a check to all arguments of that function. The specifications
|
number is going to apply a check to all arguments of that function. The specifications
|
||||||
for individual arguments override this setting.</para>
|
for individual arguments override this setting.</para>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<title>Uninitialized memory</title>
|
<title>Uninitialized memory</title>
|
||||||
|
|
||||||
|
@ -826,16 +834,19 @@ Checking pen1.c...
|
||||||
<literal>Cppcheck</literal> assumes that it is fine to pass
|
<literal>Cppcheck</literal> assumes that it is fine to pass
|
||||||
uninitialized variables to functions:</para>
|
uninitialized variables to functions:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck uninit.c
|
<programlisting># cppcheck uninit.c
|
||||||
Checking uninit.c...</programlisting>
|
Checking uninit.c...</programlisting>
|
||||||
|
|
||||||
<para>If you provide a configuration file then Cppcheck detects
|
<para>If you provide a configuration file then Cppcheck detects
|
||||||
the bug:</para>
|
the bug:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck --library=windows.cfg uninit.c
|
<programlisting># cppcheck --library=windows.cfg uninit.c
|
||||||
Checking uninit.c...
|
Checking uninit.c...
|
||||||
[uninit.c:5]: (error) Uninitialized variable: buffer2</programlisting>
|
[uninit.c:5]: (error) Uninitialized variable: buffer2</programlisting>
|
||||||
|
|
||||||
|
<para>Note that this implies for pointers that the memory they point
|
||||||
|
at has to be initialized, too.</para>
|
||||||
|
|
||||||
<para>Here is the minimal <literal>windows.cfg</literal>:</para>
|
<para>Here is the minimal <literal>windows.cfg</literal>:</para>
|
||||||
|
|
||||||
<para><programlisting><?xml version="1.0"?>
|
<para><programlisting><?xml version="1.0"?>
|
||||||
|
@ -865,16 +876,20 @@ Checking uninit.c...
|
||||||
let's assume it's bad. Cppcheck assumes that it's ok to pass NULL to
|
let's assume it's bad. Cppcheck assumes that it's ok to pass NULL to
|
||||||
functions so no error is reported:</para>
|
functions so no error is reported:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck null.c
|
<programlisting># cppcheck null.c
|
||||||
Checking null.c...</programlisting>
|
Checking null.c...</programlisting>
|
||||||
|
|
||||||
<para>If you provide a windows configuration file then
|
<para>If you provide a configuration file then
|
||||||
<literal>Cppcheck</literal> detects the bug:</para>
|
<literal>Cppcheck</literal> detects the bug:</para>
|
||||||
|
|
||||||
<programlisting>cppcheck --library=windows.cfg null.c
|
<programlisting>cppcheck --library=windows.cfg null.c
|
||||||
Checking null.c...
|
Checking null.c...
|
||||||
[null.c:3]: (error) Null pointer dereference</programlisting>
|
[null.c:3]: (error) Null pointer dereference</programlisting>
|
||||||
|
|
||||||
|
<para>Note that this implies <literal><not-uninit></literal> as
|
||||||
|
far as values are concerned. Uninitialized memory might still be passed
|
||||||
|
do the function.</para>
|
||||||
|
|
||||||
<para>Here is a minimal <literal>windows.cfg</literal> file:</para>
|
<para>Here is a minimal <literal>windows.cfg</literal> file:</para>
|
||||||
|
|
||||||
<programlisting><?xml version="1.0"?>
|
<programlisting><?xml version="1.0"?>
|
||||||
|
@ -902,7 +917,7 @@ Checking null.c...
|
||||||
|
|
||||||
<para>No error is reported for that:</para>
|
<para>No error is reported for that:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck formatstring.c
|
<programlisting># cppcheck formatstring.c
|
||||||
Checking formatstring.c...</programlisting>
|
Checking formatstring.c...</programlisting>
|
||||||
|
|
||||||
<para>A configuration file can be created that says that the string is a
|
<para>A configuration file can be created that says that the string is a
|
||||||
|
@ -918,7 +933,7 @@ Checking null.c...
|
||||||
</function>
|
</function>
|
||||||
</def></programlisting>Now Cppcheck will report an error:</para>
|
</def></programlisting>Now Cppcheck will report an error:</para>
|
||||||
|
|
||||||
<programlisting>cppcheck --library=test.cfg formatstring.c
|
<programlisting>cppcheck --library=test.cfg formatstring.c
|
||||||
Checking formatstring.c...
|
Checking formatstring.c...
|
||||||
[formatstring.c:3]: (error) do_something format string requires 2 parameters but only 1 is given.</programlisting>
|
[formatstring.c:3]: (error) do_something format string requires 2 parameters but only 1 is given.</programlisting>
|
||||||
|
|
||||||
|
@ -947,7 +962,7 @@ Checking formatstring.c...
|
||||||
|
|
||||||
<para>No error is reported for that:</para>
|
<para>No error is reported for that:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck valuerange.c
|
<programlisting># cppcheck valuerange.c
|
||||||
Checking valuerange.c...</programlisting>
|
Checking valuerange.c...</programlisting>
|
||||||
|
|
||||||
<para>A configuration file can be created that says that 1024 is out of
|
<para>A configuration file can be created that says that 1024 is out of
|
||||||
|
@ -962,7 +977,7 @@ Checking valuerange.c...</programlisting>
|
||||||
</function>
|
</function>
|
||||||
</def></programlisting>Now Cppcheck will report an error:</para>
|
</def></programlisting>Now Cppcheck will report an error:</para>
|
||||||
|
|
||||||
<programlisting>cppcheck --library=test.cfg range.c
|
<programlisting>cppcheck --library=test.cfg range.c
|
||||||
Checking range.c...
|
Checking range.c...
|
||||||
[range.c:3]: (error) Invalid do_something() argument nr 1. The value is 1024 but the valid values are '0-1023'.</programlisting>
|
[range.c:3]: (error) Invalid do_something() argument nr 1. The value is 1024 but the valid values are '0-1023'.</programlisting>
|
||||||
|
|
||||||
|
@ -990,7 +1005,7 @@ Checking range.c...
|
||||||
|
|
||||||
<para>No error is reported for that:</para>
|
<para>No error is reported for that:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck minsize.c
|
<programlisting># cppcheck minsize.c
|
||||||
Checking minsize.c...</programlisting>
|
Checking minsize.c...</programlisting>
|
||||||
|
|
||||||
<para>A configuration file can for instance be created that says that
|
<para>A configuration file can for instance be created that says that
|
||||||
|
@ -1075,13 +1090,13 @@ Checking minsize.c...
|
||||||
<para>In theory, if <literal>ZeroMemory</literal> terminates the program
|
<para>In theory, if <literal>ZeroMemory</literal> terminates the program
|
||||||
then there is no bug. Cppcheck therefore reports no error:</para>
|
then there is no bug. Cppcheck therefore reports no error:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck noreturn.c
|
<programlisting># cppcheck noreturn.c
|
||||||
Checking noreturn.c...</programlisting>
|
Checking noreturn.c...</programlisting>
|
||||||
|
|
||||||
<para>However if you use <literal>--check-library</literal> and
|
<para>However if you use <literal>--check-library</literal> and
|
||||||
<literal>--enable=information</literal> you'll get this:</para>
|
<literal>--enable=information</literal> you'll get this:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck --check-library --enable=information noreturn.c
|
<programlisting># cppcheck --check-library --enable=information noreturn.c
|
||||||
Checking noreturn.c...
|
Checking noreturn.c...
|
||||||
[noreturn.c:7]: (information) --check-library: Function ZeroMemory() should have <noreturn> configuration
|
[noreturn.c:7]: (information) --check-library: Function ZeroMemory() should have <noreturn> configuration
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
@ -1089,7 +1104,7 @@ Checking noreturn.c...
|
||||||
<para>If a proper <literal>windows.cfg</literal> is provided, the bug is
|
<para>If a proper <literal>windows.cfg</literal> is provided, the bug is
|
||||||
detected:</para>
|
detected:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck --library=windows.cfg noreturn.c
|
<programlisting># cppcheck --library=windows.cfg noreturn.c
|
||||||
Checking noreturn.c...
|
Checking noreturn.c...
|
||||||
[noreturn.c:8]: (error) Uninitialized variable: data</programlisting>
|
[noreturn.c:8]: (error) Uninitialized variable: data</programlisting>
|
||||||
|
|
||||||
|
@ -1119,13 +1134,13 @@ Checking noreturn.c...
|
||||||
assigning the result to one of the parameters passed to it, nothing bad
|
assigning the result to one of the parameters passed to it, nothing bad
|
||||||
would happen:</para>
|
would happen:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck useretval.c
|
<programlisting># cppcheck useretval.c
|
||||||
Checking useretval.c...</programlisting>
|
Checking useretval.c...</programlisting>
|
||||||
|
|
||||||
<para>If a proper <literal>lib.cfg</literal> is provided, the bug is
|
<para>If a proper <literal>lib.cfg</literal> is provided, the bug is
|
||||||
detected:</para>
|
detected:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck --library=lib.cfg --enable=warning useretval.c
|
<programlisting># cppcheck --library=lib.cfg --enable=warning useretval.c
|
||||||
Checking useretval.c...
|
Checking useretval.c...
|
||||||
[noreturn.c:3]: (warning) Return value of function strcmp() is not used.</programlisting>
|
[noreturn.c:3]: (warning) Return value of function strcmp() is not used.</programlisting>
|
||||||
|
|
||||||
|
@ -1206,7 +1221,7 @@ Checking useretval.c...
|
||||||
|
|
||||||
<para>No message about variable 'a' being unused is printed:</para>
|
<para>No message about variable 'a' being unused is printed:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck --enable=style unusedvar.cpp
|
<programlisting># cppcheck --enable=style unusedvar.cpp
|
||||||
Checking unusedvar.cpp...</programlisting>
|
Checking unusedvar.cpp...</programlisting>
|
||||||
|
|
||||||
<para>If uint16_t is defined in a library as follows, the result
|
<para>If uint16_t is defined in a library as follows, the result
|
||||||
|
@ -1221,7 +1236,7 @@ Checking unusedvar.cpp...</programlisting>
|
||||||
the "sign" attribute are "s" (signed) and "u" (unsigned). Both
|
the "sign" attribute are "s" (signed) and "u" (unsigned). Both
|
||||||
attributes are optional. Using this library, cppcheck prints:</para>
|
attributes are optional. Using this library, cppcheck prints:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck --library=lib.cfg --enable=style unusedvar.cpp
|
<programlisting># cppcheck --library=lib.cfg --enable=style unusedvar.cpp
|
||||||
Checking unusedvar.cpp...
|
Checking unusedvar.cpp...
|
||||||
[unusedvar.cpp:2]: (style) Unused variable: a</programlisting>
|
[unusedvar.cpp:2]: (style) Unused variable: a</programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Reference in New Issue