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