From e0b77a975f4a502cc9c5dc449b85afff66b12cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 31 Jan 2015 11:20:36 +0100 Subject: [PATCH] Manual: Tweaked the cfg documentation --- man/manual.docbook | 63 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/man/manual.docbook b/man/manual.docbook index e3a80b7a8..46947dbac 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -690,9 +690,11 @@ Checking uninit.c... <?xml version="1.0"?> <def> <function name="CopyMemory"> + <arg nr="1"/> <arg nr="2"> <not-uninit/> </arg> + <arg nr="3"/> </function> </def> @@ -730,6 +732,8 @@ Checking null.c... <arg nr="1"> <not-null/> </arg> + <arg nr="2"/> + <arg nr="3"/> </function> </def> @@ -789,7 +793,7 @@ Checking valuerange.c... <def> <function name="do_something"> <arg nr="1"> - <valid>0-1023</valid> + <valid>0:1023</valid> </arg> </function> </def>Now Cppcheck will report an error: @@ -797,6 +801,14 @@ Checking valuerange.c... cppcheck --library=test.cfg 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'. + + Some example expressions you can use in the valid element: + + 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
@@ -849,7 +861,8 @@ Checking noreturn.c...
use-retval - As long as nothing else is specified, cppcheck assumes that ignoring the return value of a function is ok: + As long as nothing else is specified, cppcheck assumes that + ignoring the return value of a function is ok: bool test(const char* a, const char* b) { @@ -857,7 +870,9 @@ Checking noreturn.c... return true; } - In case strcmp has side effects, such as assigning the result to one of the parameters passed to it, nothing bad would happen: + In case strcmp has side effects, such as + assigning the result to one of the parameters passed to it, nothing bad + would happen: # cppcheck useretval.c Checking useretval.c... @@ -882,20 +897,25 @@ Checking useretval.c...
define - Libraries can be used to define preprocessor macros as well. For example: + Libraries can be used to define preprocessor macros as well. For + example: <?xml version="1.0"?> <def> <define name="NULL_VALUE" value="0"/> </def> - Each occurence of "NULL_VALUE" in the code would then be replaced by "0" at preprocessor stage. + Each occurence of "NULL_VALUE" in the code would then be replaced + by "0" at preprocessor stage.
podtype - 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: + 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: void test() { uint16_t a; @@ -906,14 +926,17 @@ Checking useretval.c... # cppcheck --enable=style unusedvar.cpp Checking unusedvar.cpp... - If uint16_t is defined in a library as follows, the result improves: + If uint16_t is defined in a library as follows, the result + improves: <?xml version="1.0"?> <def> <podtype name="uint16_t" sign="u" size="2"/> </def> - 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: + 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: # cppcheck --library=lib.cfg --enable=style unusedvar.cpp Checking unusedvar.cpp... @@ -923,11 +946,21 @@ Checking unusedvar.cpp...
container - 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. + 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. - 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". + 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". - The following example provides a definition for std::vector, based on the definition of "stdContainer" (not shown): + The following example provides a definition for std::vector, based + on the definition of "stdContainer" (not shown): <?xml version="1.0"?> <def> @@ -943,7 +976,6 @@ Checking unusedvar.cpp... </access> </container> </def> -
@@ -961,6 +993,7 @@ Checking unusedvar.cpp... <arg nr="2"> <not-null/> <not-uninit/> + <strz/> </arg> </function> @@ -978,7 +1011,8 @@ Checking unusedvar.cpp... The second argument the function takes is a pointer. It must not be null. And it must point at initialized data. Using <not-null> and - <not-uninit> is correct. + <not-uninit> is correct. Moreover it must point + at a zero-terminated string so <strz> is also used.
@@ -1016,7 +1050,8 @@ Checking unusedvar.cpp... </message> </rule> - CDATA can be used to include characters in a pattern that might interfere with XML: + CDATA can be used to include characters in a pattern that might + interfere with XML: <![CDATA[some<strange>pattern]]>