diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 1f10a8131..35cb2e900 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -743,8 +743,10 @@ void CmdLineParser::PrintHelp() " by providing an implementation for them.\n" " --check-config Check cppcheck configuration. The normal code\n" " analysis is disabled by this flag.\n" - " -D By default Cppcheck checks all configurations. Use -D\n" - " to limit the checking to a particular configuration.\n" + " -D By default Cppcheck checks all configurations. When -D\n" + " is used, Cppcheck only checks the given configuration.\n" + " But you can also use --force or --max-configs to check\n" + " multiple configurations.\n" " Example: '-DDEBUG=1 -D__cplusplus'.\n" " -U By default Cppcheck checks all configurations. Use -U\n" " to explicitly hide certain #ifdef code paths from\n" @@ -753,6 +755,8 @@ void CmdLineParser::PrintHelp() " --enable= Enable additional checks. The available ids are:\n" " * all\n" " Enable all checks\n" + " * warning\n" + " Enable warning messages" " * style\n" " Enable all coding style checks. All messages\n" " with the severities 'style', 'performance' and\n" diff --git a/man/manual.docbook b/man/manual.docbook index 7e4dd7b8c..67adb6dc3 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -104,9 +104,10 @@ Checking path/file2.cpp... All files under src/a and src/b are then checked. - The second option is to use -i, - with it you specify files/paths to ignore. With this command no files in - src/c are checked: + The second option is to use -i, with it you specify files/paths to + ignore. With this command no files in src/c are checked: cppcheck -isrc/c src @@ -147,9 +148,10 @@ Checking path/file2.cpp... performance - Suggestions for making the code faster. These suggestions are - only based on common knowledge. It is not certain you'll get any - measurable difference in speed by fixing these messages. + Suggestions for making the code faster. These suggestions + are only based on common knowledge. It is not certain you'll get + any measurable difference in speed by fixing these + messages. @@ -175,67 +177,42 @@ Checking path/file2.cpp...
Enable messages - By default only error messages - are shown. Through the --enable - command more checks can be enabled. + By default only error + messages are shown. Through the --enable command more checks can be + enabled. -
- Stylistic issues + # enable warning messages +cppcheck --enable=warning file.c - With --enable=style you - enable most warning, - style and - performance messages. +# enable performance messages +cppcheck --enable=performance file.c - Here is a simple code example: +# enable information messages +cppcheck --enable=information file.c - void f(int x) -{ - int i; - if (x == 0) - { - i = 0; - } -} +# For historical reasons, --enable=style enables warning, performance, +# portability and style messages. These are all reported as "style" when +# using the old xml format. +cppcheck --enable=style file.c - There are no bugs in that code so Cppcheck won't report anything - by default. To enable the stylistic messages, use the - --enable=style command: +# enable warning and information messages +cppcheck --enable=warning,information file.c - cppcheck --enable=style file3.c +# enable unusedFunction checking. This is not enabled by --enable=style +# because it doesn't work well on libraries. +cppcheck --enable=unusedFunction file.c - The output from Cppcheck is now: - - Checking file3.c... -[file3.c:3]: (style) Variable 'i' is assigned a value that is never used -[file3.c:3]: (style) The scope of the variable i can be reduced -
- -
- Unused functions - - This check will try to find unused functions. It is best to use - this when the whole program is checked, so that all usages is seen by - cppcheck. - - cppcheck --enable=unusedFunction path -
- -
- Enable all checks - - To enable all checks your can use the - --enable=all flag: - - cppcheck --enable=all path -
+# enable all messages +cppcheck --enable=all
Inconclusive checks By default Cppcheck only writes error messages if it is certain. With --inconclusive error - messages will also be written when the analysis is inconclusive. + messages will also be written when the analysis is + inconclusive. cppcheck --inconclusive path @@ -258,8 +235,9 @@ Checking path/file2.cpp...
Multithreaded checking - The option -j is used to specify the number of threads you want to use. - For example, to use 4 threads to check the files in a folder: + The option -j is used to specify the number of threads you want to + use. For example, to use 4 threads to check the files in a + folder: cppcheck -j 4 path
@@ -269,22 +247,30 @@ Checking path/file2.cpp... Preprocessor configurations By default Cppcheck will check all preprocessor configurations - (except those that have #error in them). This is the recommended - behaviour. + (except those that have #error in them). - But if you want to manually limit the checking you can do so with - -D. + 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. - Beware that only the macros, which are given here and the macros - defined in source files and known header files are considered. That - excludes all the macros defined in some system header files, which are by - default not examined by Cppcheck. + # check all configurations +cppcheck file.c - The usage: if you, for example, want to limit the checking so the - only configuration to check should be DEBUG=1;__cplusplus - then something like this can be used: +# only check the configuration A +cppcheck -DA file.c - cppcheck -DDEBUG=1 -D__cplusplus path +# check all configurations when macro A is defined +cppcheck -DA --force file.c + + Another useful flag might be -U. It undefines a symbol. Example + usage: + + cppcheck -UX file.c + + That will mean that X is not defined. Cppcheck will not check what + happens when X is defined. @@ -403,7 +389,7 @@ Checking path/file2.cpp... this attribute doesn't exist yet. But in the future we may - add a short message for each location. + add a short message for each location. @@ -416,8 +402,8 @@ Checking path/file2.cpp... If you want to reformat the output so it looks different you can use templates. - To get Visual Studio compatible output you can use - --template=vs: + To get Visual Studio compatible output you can use --template=vs: cppcheck --template=vs gui/test.cpp @@ -427,8 +413,8 @@ Checking path/file2.cpp... gui/test.cpp(31): error: Memory leak: b gui/test.cpp(16): error: Mismatching allocation and deallocation: k - To get gcc compatible output you can use - --template=gcc: + To get gcc compatible output you can use --template=gcc: cppcheck --template=gcc gui/test.cpp @@ -449,7 +435,8 @@ gui/test.cpp:16: error: Mismatching allocation and deallocation: k - The escape sequences \b (backspace), \n (newline), \r (formfeed) and \t (horizontal tab) are supported. + The escape sequences \b (backspace), \n (newline), \r (formfeed) and + \t (horizontal tab) are supported. @@ -558,9 +545,8 @@ Checking test.c...
User-defined allocation/deallocation functions - Cppcheck understands standard allocation and - deallocation functions. But it doesn't know what library functions - do. + Cppcheck understands standard allocation and deallocation + functions. But it doesn't know what library functions do. Here is example code that might leak memory or resources: @@ -591,8 +577,8 @@ void DestroyFred(void *p) } When Cppcheck see this it understands that CreateFred() - will return allocated memory and that DestroyFred() - will deallocate memory. + will return allocated memory and that + DestroyFred() will deallocate memory. Now, execute cppcheck this way: @@ -609,11 +595,11 @@ void DestroyFred(void *p) HTML report You can convert the XML output from cppcheck into a HTML report. - You'll need Python and the pygments module - (http://pygments.org/) for this to - work. In the Cppcheck source tree there is a folder - htmlreport that contains a script - that transforms a Cppcheck XML file into HTML output. + You'll need Python and the pygments module (http://pygments.org/) for this to work. + In the Cppcheck source tree there is a folder htmlreport that contains a script that + transforms a Cppcheck XML file into HTML output. This command generates the help screen: @@ -675,9 +661,11 @@ htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.< The language can be changed at any time by using the Language menu. - More settings are available in - EditPreferences - . + More settings are available in + Edit + + Preferences + .
@@ -696,9 +684,10 @@ htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.< - As you can read in chapter - 3 in this manual the default is that Cppcheck checks all configurations. - So only provide preprocessor defines if you want to limit the checking. + As you can read in chapter 3 in this manual + the default is that Cppcheck checks all configurations. So only provide + preprocessor defines if you want to limit the checking.