Manual: Tweaked the cfg documentation
This commit is contained in:
parent
7e50d7a1d0
commit
e0b77a975f
|
@ -690,9 +690,11 @@ Checking uninit.c...
|
||||||
<para><programlisting><?xml version="1.0"?>
|
<para><programlisting><?xml version="1.0"?>
|
||||||
<def>
|
<def>
|
||||||
<function name="CopyMemory">
|
<function name="CopyMemory">
|
||||||
|
<arg nr="1"/>
|
||||||
<arg nr="2">
|
<arg nr="2">
|
||||||
<not-uninit/>
|
<not-uninit/>
|
||||||
</arg>
|
</arg>
|
||||||
|
<arg nr="3"/>
|
||||||
</function>
|
</function>
|
||||||
</def></programlisting></para>
|
</def></programlisting></para>
|
||||||
</section>
|
</section>
|
||||||
|
@ -730,6 +732,8 @@ Checking null.c...
|
||||||
<arg nr="1">
|
<arg nr="1">
|
||||||
<not-null/>
|
<not-null/>
|
||||||
</arg>
|
</arg>
|
||||||
|
<arg nr="2"/>
|
||||||
|
<arg nr="3"/>
|
||||||
</function>
|
</function>
|
||||||
</def></programlisting>
|
</def></programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
@ -789,7 +793,7 @@ Checking valuerange.c...</programlisting>
|
||||||
<def>
|
<def>
|
||||||
<function name="do_something">
|
<function name="do_something">
|
||||||
<arg nr="1">
|
<arg nr="1">
|
||||||
<valid>0-1023</valid>
|
<valid>0:1023</valid>
|
||||||
</arg>
|
</arg>
|
||||||
</function>
|
</function>
|
||||||
</def></programlisting>Now Cppcheck will report an error:</para>
|
</def></programlisting>Now Cppcheck will report an error:</para>
|
||||||
|
@ -797,6 +801,14 @@ Checking valuerange.c...</programlisting>
|
||||||
<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>
|
||||||
|
|
||||||
|
<para>Some example expressions you can use in the valid element:</para>
|
||||||
|
|
||||||
|
<programlisting>0,3,5 => only values 0, 3 and 5 are valid
|
||||||
|
-10:20 => all values between -10 and 20 are valid
|
||||||
|
:0 => all values that are less or equal to 0 are valid
|
||||||
|
0: => all values that are greater or equal to 0 are valid
|
||||||
|
0,2:32 => the value 0 and all values between 2 and 32 are valid </programlisting>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
@ -849,7 +861,8 @@ Checking noreturn.c...
|
||||||
<section>
|
<section>
|
||||||
<title>use-retval</title>
|
<title>use-retval</title>
|
||||||
|
|
||||||
<para>As long as nothing else is specified, cppcheck assumes that ignoring the return value of a function is ok:</para>
|
<para>As long as nothing else is specified, cppcheck assumes that
|
||||||
|
ignoring the return value of a function is ok:</para>
|
||||||
|
|
||||||
<programlisting>bool test(const char* a, const char* b)
|
<programlisting>bool test(const char* a, const char* b)
|
||||||
{
|
{
|
||||||
|
@ -857,7 +870,9 @@ Checking noreturn.c...
|
||||||
return true;
|
return true;
|
||||||
}</programlisting>
|
}</programlisting>
|
||||||
|
|
||||||
<para>In case <literal>strcmp</literal> has side effects, such as assigning the result to one of the parameters passed to it, nothing bad would happen:</para>
|
<para>In case <literal>strcmp</literal> has side effects, such as
|
||||||
|
assigning the result to one of the parameters passed to it, nothing bad
|
||||||
|
would happen:</para>
|
||||||
|
|
||||||
<programlisting># cppcheck useretval.c
|
<programlisting># cppcheck useretval.c
|
||||||
Checking useretval.c...</programlisting>
|
Checking useretval.c...</programlisting>
|
||||||
|
@ -882,20 +897,25 @@ Checking useretval.c...
|
||||||
<section>
|
<section>
|
||||||
<title>define</title>
|
<title>define</title>
|
||||||
|
|
||||||
<para>Libraries can be used to define preprocessor macros as well. For example:</para>
|
<para>Libraries can be used to define preprocessor macros as well. For
|
||||||
|
example:</para>
|
||||||
|
|
||||||
<programlisting><?xml version="1.0"?>
|
<programlisting><?xml version="1.0"?>
|
||||||
<def>
|
<def>
|
||||||
<define name="NULL_VALUE" value="0"/>
|
<define name="NULL_VALUE" value="0"/>
|
||||||
</def></programlisting>
|
</def></programlisting>
|
||||||
|
|
||||||
<para>Each occurence of "NULL_VALUE" in the code would then be replaced by "0" at preprocessor stage.</para>
|
<para>Each occurence of "NULL_VALUE" in the code would then be replaced
|
||||||
|
by "0" at preprocessor stage.</para>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<title>podtype</title>
|
<title>podtype</title>
|
||||||
|
|
||||||
<para>Lots of code relies on typedefs providing platform independant types. "podtype"-tags can be used to provide necessary information to cppcheck to support them. Without further information, cppcheck does not understand the type "uint16_t" in the following example:</para>
|
<para>Lots of code relies on typedefs providing platform independant
|
||||||
|
types. "podtype"-tags can be used to provide necessary information to
|
||||||
|
cppcheck to support them. Without further information, cppcheck does not
|
||||||
|
understand the type "uint16_t" in the following example:</para>
|
||||||
|
|
||||||
<programlisting>void test() {
|
<programlisting>void test() {
|
||||||
uint16_t a;
|
uint16_t a;
|
||||||
|
@ -906,14 +926,17 @@ Checking useretval.c...
|
||||||
<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 improves:</para>
|
<para>If uint16_t is defined in a library as follows, the result
|
||||||
|
improves:</para>
|
||||||
|
|
||||||
<programlisting><?xml version="1.0"?>
|
<programlisting><?xml version="1.0"?>
|
||||||
<def>
|
<def>
|
||||||
<podtype name="uint16_t" sign="u" size="2"/>
|
<podtype name="uint16_t" sign="u" size="2"/>
|
||||||
</def></programlisting>
|
</def></programlisting>
|
||||||
|
|
||||||
<para>The size of the type is specified in bytes. Possible values for the "sign" attribute are "s" (signed) and "u" (unsigned). Both attributes are optional. Using this library, cppcheck prints:</para>
|
<para>The size of the type is specified in bytes. Possible values for
|
||||||
|
the "sign" attribute are "s" (signed) and "u" (unsigned). Both
|
||||||
|
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...
|
||||||
|
@ -923,11 +946,21 @@ Checking unusedvar.cpp...
|
||||||
<section>
|
<section>
|
||||||
<title>container</title>
|
<title>container</title>
|
||||||
|
|
||||||
<para>A lot of C++ libraries, among those the STL itself, provide containers with very similar functionality. Libraries can be used to tell cppcheck about their behaviour. Each container needs a unique ID. It can optionally have a startPattern, which must be a valid Token::Match pattern and an endPattern that is compared to the linked token of the first token with such a link. The optional attribute "inherits" takes an ID from a previously defined container.</para>
|
<para>A lot of C++ libraries, among those the STL itself, provide
|
||||||
|
containers with very similar functionality. Libraries can be used to
|
||||||
|
tell cppcheck about their behaviour. Each container needs a unique ID.
|
||||||
|
It can optionally have a startPattern, which must be a valid
|
||||||
|
Token::Match pattern and an endPattern that is compared to the linked
|
||||||
|
token of the first token with such a link. The optional attribute
|
||||||
|
"inherits" takes an ID from a previously defined container.</para>
|
||||||
|
|
||||||
<para>Inside the <container> tag, functions can be defined inside of the tags <size>, <access> and <other> (on your choice). Each of them can specify an action like "resize" and/or the result it yields, for example "end-iterator".</para>
|
<para>Inside the <container> tag, functions can be defined inside
|
||||||
|
of the tags <size>, <access> and <other> (on your
|
||||||
|
choice). Each of them can specify an action like "resize" and/or the
|
||||||
|
result it yields, for example "end-iterator".</para>
|
||||||
|
|
||||||
<para>The following example provides a definition for std::vector, based on the definition of "stdContainer" (not shown):</para>
|
<para>The following example provides a definition for std::vector, based
|
||||||
|
on the definition of "stdContainer" (not shown):</para>
|
||||||
|
|
||||||
<programlisting><?xml version="1.0"?>
|
<programlisting><?xml version="1.0"?>
|
||||||
<def>
|
<def>
|
||||||
|
@ -943,7 +976,6 @@ Checking unusedvar.cpp...
|
||||||
</access>
|
</access>
|
||||||
</container>
|
</container>
|
||||||
</def></programlisting>
|
</def></programlisting>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
@ -961,6 +993,7 @@ Checking unusedvar.cpp...
|
||||||
<arg nr="2">
|
<arg nr="2">
|
||||||
<not-null/>
|
<not-null/>
|
||||||
<not-uninit/>
|
<not-uninit/>
|
||||||
|
<strz/>
|
||||||
</arg>
|
</arg>
|
||||||
</function></programlisting>
|
</function></programlisting>
|
||||||
|
|
||||||
|
@ -978,7 +1011,8 @@ Checking unusedvar.cpp...
|
||||||
<para>The second argument the function takes is a pointer. It must not
|
<para>The second argument the function takes is a pointer. It must not
|
||||||
be null. And it must point at initialized data. Using
|
be null. And it must point at initialized data. Using
|
||||||
<literal><not-null></literal> and
|
<literal><not-null></literal> and
|
||||||
<literal><not-uninit></literal> is correct.</para>
|
<literal><not-uninit></literal> is correct. Moreover it must point
|
||||||
|
at a zero-terminated string so <strz> is also used.</para>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
@ -1016,7 +1050,8 @@ Checking unusedvar.cpp...
|
||||||
</message>
|
</message>
|
||||||
</rule></programlisting>
|
</rule></programlisting>
|
||||||
|
|
||||||
<para>CDATA can be used to include characters in a pattern that might interfere with XML:</para>
|
<para>CDATA can be used to include characters in a pattern that might
|
||||||
|
interfere with XML:</para>
|
||||||
|
|
||||||
<programlisting><![CDATA[some<strange>pattern]]></programlisting>
|
<programlisting><![CDATA[some<strange>pattern]]></programlisting>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue