manual.docbook: added documentation about <not-bool> and <pure>
This commit is contained in:
parent
45a3bf6f6f
commit
4e338e952d
|
@ -690,6 +690,11 @@ Checking test.c...
|
||||||
<literal>--enable=information</literal> to get hints about what you
|
<literal>--enable=information</literal> to get hints about what you
|
||||||
should configure.</para>
|
should configure.</para>
|
||||||
|
|
||||||
|
<para>It is recommended that you use the <literal>Library
|
||||||
|
Editor</literal> in the <literal>Cppcheck GUI</literal> to edit
|
||||||
|
configuration files. It is available in the <literal>View</literal>
|
||||||
|
menu. All settings are not documented in this manual.</para>
|
||||||
|
|
||||||
<para>The command line cppcheck will try to load custom .cfg files from
|
<para>The command line cppcheck will try to load custom .cfg files from
|
||||||
the working path - execute cppcheck from the path where the .cfg files
|
the working path - execute cppcheck from the path where the .cfg files
|
||||||
are.</para>
|
are.</para>
|
||||||
|
@ -805,7 +810,9 @@ Checking pen1.c...
|
||||||
attribute and their number of arguments. The name is a comma-separated
|
attribute and their number of arguments. The name is a comma-separated
|
||||||
list of function names. For functions in namespaces or classes, just
|
list of function names. For functions in namespaces or classes, just
|
||||||
provide their fully qualified name. For example: <literal><function
|
provide their fully qualified name. For example: <literal><function
|
||||||
name="memcpy,std::memcpy"></literal>.</para>
|
name="memcpy,std::memcpy"></literal>. If you have template functions
|
||||||
|
then provide their instantiated names <literal><function
|
||||||
|
name="dostuff<int>"></literal>.</para>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<title>Function arguments</title>
|
<title>Function arguments</title>
|
||||||
|
@ -820,6 +827,43 @@ Checking pen1.c...
|
||||||
that function. The specifications for individual arguments override
|
that function. The specifications for individual arguments override
|
||||||
this setting.</para>
|
this setting.</para>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<title>Not bool</title>
|
||||||
|
|
||||||
|
<para>Here is an example program with misplaced comparison:</para>
|
||||||
|
|
||||||
|
<programlisting>void test()
|
||||||
|
{
|
||||||
|
if (MemCmp(buffer1, buffer2, 1024==0)) {}
|
||||||
|
}</programlisting>
|
||||||
|
|
||||||
|
<para><literal>Cppcheck</literal> assumes that it is fine to pass
|
||||||
|
boolean values to functions:</para>
|
||||||
|
|
||||||
|
<programlisting># cppcheck notbool.c
|
||||||
|
Checking notbool.c...</programlisting>
|
||||||
|
|
||||||
|
<para>If you provide a configuration file then Cppcheck detects the
|
||||||
|
bug:</para>
|
||||||
|
|
||||||
|
<programlisting># cppcheck --library=notbool.cfg notbool.c
|
||||||
|
Checking notbool.c...
|
||||||
|
[notbool.c:5]: (error) Invalid MemCmp() argument nr 3. A non-boolean value is required.</programlisting>
|
||||||
|
|
||||||
|
<para>Here is the minimal notbool.cfg</para>
|
||||||
|
|
||||||
|
<para><programlisting><?xml version="1.0"?>
|
||||||
|
<def>
|
||||||
|
<function name="MemCmp">
|
||||||
|
<arg nr="1"/>
|
||||||
|
<arg nr="2"/>
|
||||||
|
<arg nr="3">
|
||||||
|
<not-bool/>
|
||||||
|
</arg>
|
||||||
|
</function>
|
||||||
|
</def></programlisting></para>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<title>Uninitialized memory</title>
|
<title>Uninitialized memory</title>
|
||||||
|
|
||||||
|
@ -1120,6 +1164,8 @@ Checking noreturn.c...
|
||||||
<def>
|
<def>
|
||||||
<function name="ZeroMemory">
|
<function name="ZeroMemory">
|
||||||
<noreturn>false</noreturn>
|
<noreturn>false</noreturn>
|
||||||
|
<arg nr="1"/>
|
||||||
|
<arg nr="2"/>
|
||||||
</function>
|
</function>
|
||||||
</def></programlisting>
|
</def></programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
@ -1148,7 +1194,7 @@ Checking useretval.c...</programlisting>
|
||||||
|
|
||||||
<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>
|
[useretval.c:3]: (warning) Return value of function strcmp() is not used.</programlisting>
|
||||||
|
|
||||||
<para>Here is a minimal <literal>lib.cfg</literal> file:</para>
|
<para>Here is a minimal <literal>lib.cfg</literal> file:</para>
|
||||||
|
|
||||||
|
@ -1156,6 +1202,47 @@ Checking useretval.c...
|
||||||
<def>
|
<def>
|
||||||
<function name="strcmp">
|
<function name="strcmp">
|
||||||
<use-retval/>
|
<use-retval/>
|
||||||
|
<arg nr="1"/>
|
||||||
|
<arg nr="2"/>
|
||||||
|
</function>
|
||||||
|
</def></programlisting>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<title>pure</title>
|
||||||
|
|
||||||
|
<para>A function that is pure will calculate a return value and has no
|
||||||
|
side effects. If the same parameters are given twice then the same
|
||||||
|
return value will be calculated twice.</para>
|
||||||
|
|
||||||
|
<programlisting>void f(int x)
|
||||||
|
{
|
||||||
|
if (calculate(x) == 213) {
|
||||||
|
|
||||||
|
} else if (calculate(x) == 213) {
|
||||||
|
// unreachable code
|
||||||
|
}
|
||||||
|
}</programlisting>
|
||||||
|
|
||||||
|
<para>Cppcheck reports no warning</para>
|
||||||
|
|
||||||
|
<programlisting># cppcheck pure.c
|
||||||
|
Checking pure.c...</programlisting>
|
||||||
|
|
||||||
|
<para>If a proper <literal>lib.cfg</literal> is provided, the
|
||||||
|
unreachable code is detected:</para>
|
||||||
|
|
||||||
|
<programlisting># cppcheck --enable=style --library=pure pure.c
|
||||||
|
Checking pure.c...
|
||||||
|
[pure.c:7]: (style) Expression is always false because 'else if' condition matches previous condition at line 5.</programlisting>
|
||||||
|
|
||||||
|
<para>Here is a minimal <literal>pure.cfg</literal> file:</para>
|
||||||
|
|
||||||
|
<programlisting><?xml version="1.0"?>
|
||||||
|
<def>
|
||||||
|
<function name="calculate">
|
||||||
|
<pure/>
|
||||||
|
<arg nr="1"/>
|
||||||
</function>
|
</function>
|
||||||
</def></programlisting>
|
</def></programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Reference in New Issue