diff --git a/man/manual.docbook b/man/manual.docbook index 4b7bc6019..b8dffac2e 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -314,8 +314,8 @@ cppcheck --enable=all You can use -D to change this. When you use -D, cppcheck will by default only check the given configuration and nothing else. This is how compilers work. But you can use --force or - --max-configs to override the number - of configurations. + --max-configs to override the number of + configurations. # check all configurations cppcheck file.c @@ -562,7 +562,7 @@ gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocati severity - a type/rank of message + a type/rank of message @@ -670,16 +670,16 @@ Checking test.c... Library configuration - When external libraries are used, such as WinAPI, POSIX, gtk, Qt, etc, - Cppcheck doesn't know how the external functions + When external libraries are used, such as WinAPI, POSIX, gtk, Qt, + etc, Cppcheck doesn't know how the external functions behave. Cppcheck then fails to detect various problems such as leaks, buffer overflows, possible null pointer dereferences, etc. But this can be fixed with configuration files. Cppcheck already contains configurations for several libraries. They - can be loaded as described below. Note that the configuration for the standard - libraries of C and C++, std.cfg, is always loaded by - cppcheck. If you create or update a configuration file for a + can be loaded as described below. Note that the configuration for the + standard libraries of C and C++, std.cfg, is always + loaded by cppcheck. If you create or update a configuration file for a popular library, we would appreciate if you upload it to us.
@@ -704,23 +704,25 @@ Checking test.c... Memory/resource leaks Cppcheck has configurable checking for leaks, e.g. you can specify - which functions allocate and free memory or resources and which functions - do not affect the allocation at all. + which functions allocate and free memory or resources and which + functions do not affect the allocation at all.
alloc and dealloc Here is an example program: - void test() + + void test() { HPEN pen = CreatePen(PS_SOLID, 1, RGB(255,0,0)); -} +} + The code example above has a resource leak - CreatePen() is a WinAPI function that creates a - pen. However, Cppcheck doesn't assume that return values from functions - must be freed. There is no error message: + pen. However, Cppcheck doesn't assume that return values from + functions must be freed. There is no error message: # cppcheck pen1.c Checking pen1.c... @@ -745,9 +747,9 @@ Checking pen1.c... The allocation and deallocation functions are organized in groups. Each group is defined in a <resource> or - <memory> tag and is identified by its <dealloc> - functions. This means, groups with overlapping <dealloc> - tags are merged. + <memory> tag and is identified by its + <dealloc> functions. This means, groups with + overlapping <dealloc> tags are merged.
leak-ignore and use @@ -788,10 +790,9 @@ Checking pen1.c... </memory> </def> - The <use> - configuration has no logical purpose. You will get the same warnings - without it. Use it to silence --check-library - information messages. + The <use> configuration has no logical + purpose. You will get the same warnings without it. Use it to silence + --check-library information messages.
@@ -799,23 +800,25 @@ Checking pen1.c... Function behaviour To specify the behaviour of functions and how they should be used, - <function> tags can be used. Functions are identified - by their name, specified in the name 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">. - + <function> tags can be used. Functions are + identified by their name, specified in the name + 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">.
Function arguments - The arguments a function takes can be specified by <arg> - tags. Each of them takes the number of the argument (starting from 1) in the - nr attribute, or nr="any" for variadic arguments. - Optional arguments can be specified by providing a default value: - default="value". Specifying -1 as the argument - number is going to apply a check to all arguments of that function. The specifications - for individual arguments override this setting. + The arguments a function takes can be specified by + <arg> tags. Each of them takes the number of + the argument (starting from 1) in the nr attribute, + or nr="any" for variadic arguments. Optional + arguments can be specified by providing a default value: + default="value". Specifying -1 + as the argument number is going to apply a check to all arguments of + that function. The specifications for individual arguments override + this setting.
Uninitialized memory @@ -829,16 +832,16 @@ Checking pen1.c... CopyMemory(buffer1, buffer2, 1024); } - The bug here is that buffer2 is uninitialized. The second argument - for CopyMemory needs to be initialized. However, + The bug here is that buffer2 is uninitialized. The second + argument for CopyMemory needs to be initialized. However, Cppcheck assumes that it is fine to pass uninitialized variables to functions: # cppcheck uninit.c Checking uninit.c... - If you provide a configuration file then Cppcheck detects - the bug: + If you provide a configuration file then Cppcheck detects the + bug: # cppcheck --library=windows.cfg uninit.c Checking uninit.c... @@ -864,8 +867,8 @@ Checking uninit.c...
Null pointers - Cppcheck assumes it's ok to pass NULL pointers to functions. Here - is an example program: + Cppcheck assumes it's ok to pass NULL pointers to functions. + Here is an example program: void test() { @@ -886,9 +889,9 @@ Checking null.c... Checking null.c... [null.c:3]: (error) Null pointer dereference - Note that this implies <not-uninit> as - far as values are concerned. Uninitialized memory might still be passed - do the function. + Note that this implies <not-uninit> + as far as values are concerned. Uninitialized memory might still be + passed do the function. Here is a minimal windows.cfg file: @@ -920,8 +923,8 @@ Checking null.c... # cppcheck formatstring.c Checking formatstring.c... - A configuration file can be created that says that the string is a - format string. For instance: + A configuration file can be created that says that the string + is a format string. For instance: <?xml version="1.0"?> <def> @@ -965,8 +968,8 @@ Checking formatstring.c... # cppcheck valuerange.c Checking valuerange.c... - A configuration file can be created that says that 1024 is out of - bounds. For instance: + A configuration file can be created that says that 1024 is out + of bounds. For instance: <?xml version="1.0"?> <def> @@ -981,7 +984,8 @@ Checking valuerange.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: + 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 @@ -1008,9 +1012,9 @@ Checking range.c... # cppcheck minsize.c Checking minsize.c... - A configuration file can for instance be created that says that - the size of the buffer in argument 1 must be larger than the strlen of - argument 2.For instance: + A configuration file can for instance be created that says + that the size of the buffer in argument 1 must be larger than the + strlen of argument 2.For instance: <?xml version="1.0"?> <def> @@ -1052,8 +1056,8 @@ Checking minsize.c... sizeof - buffer size must be larger than other argument buffer size. - Example: see strncpy configuration in std.cfg + buffer size must be larger than other argument buffer + size. Example: see strncpy configuration in std.cfg @@ -1061,16 +1065,17 @@ Checking minsize.c... mul - buffer size must be larger than multiplication result when - multiplying values given in two other arguments. Typically one - argument defines the element size and another element defines the - number of elements. Example: see fread configuration in - std.cfg + buffer size must be larger than multiplication result + when multiplying values given in two other arguments. + Typically one argument defines the element size and another + element defines the number of elements. Example: see fread + configuration in std.cfg
+
noreturn @@ -1087,8 +1092,9 @@ Checking minsize.c... buffer[0] = data; // <- error: data is uninitialized if x is not 1 } - In theory, if ZeroMemory terminates the program - then there is no bug. Cppcheck therefore reports no error: + In theory, if ZeroMemory terminates the + program then there is no bug. Cppcheck therefore reports no + error: # cppcheck noreturn.c Checking noreturn.c... @@ -1101,8 +1107,8 @@ Checking noreturn.c... [noreturn.c:7]: (information) --check-library: Function ZeroMemory() should have <noreturn> configuration - If a proper windows.cfg is provided, the bug is - detected: + If a proper windows.cfg is provided, the bug + is detected: # cppcheck --library=windows.cfg noreturn.c Checking noreturn.c... @@ -1131,8 +1137,8 @@ Checking noreturn.c... } In case strcmp has side effects, such as - assigning the result to one of the parameters passed to it, nothing bad - would happen: + assigning the result to one of the parameters passed to it, nothing + bad would happen: # cppcheck useretval.c Checking useretval.c... @@ -1157,10 +1163,10 @@ Checking useretval.c...
Example configuration for strcpy() - The proper configuration for the standard strcpy() function would - be: + The proper configuration for the standard strcpy() function + would be: - <function name="strcpy"> + <function name="strcpy"> <leak-ignore/> <noreturn>false</noreturn> <arg nr="1"> @@ -1181,14 +1187,14 @@ Checking useretval.c... function returns or not. The first argument that the function takes is a pointer. It must - not be a null pointer, therefore <not-null> is - used. + not be a null pointer, therefore <not-null> + is used. 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. Moreover it must point - at a zero-terminated string so <strz> is also used. + <not-uninit> is correct. Moreover it must + point at a zero-terminated string so <strz> is also used.