From 364900c5c01bc18d54575538ba3c1fbfbb2bf568 Mon Sep 17 00:00:00 2001 From: Tim Gerundt Date: Sat, 2 Jul 2011 14:04:13 +0200 Subject: [PATCH] Manual: Miscellaneous tag changes --- man/manual.docbook | 28 +++++++++++++++------------- man/writing-rules-1.docbook | 14 ++++++++------ man/writing-rules-2.docbook | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/man/manual.docbook b/man/manual.docbook index 5dd33e95c..6d14a173c 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -434,13 +434,13 @@ uninitvar Here is example code that might leak memory or resources: - void foo(int x) + void foo(int x) { void *f = CreateFred(); if (x == 1) return; DestroyFred(f); -} +} If you analyse that with Cppcheck it won't find any leaks: @@ -460,8 +460,9 @@ void DestroyFred(void *p) free(p); } - When Cppcheck see this it understands that CreateFred will return - allocated memory and that DestroyFred will deallocate memory. + When Cppcheck see this it understands that CreateFred() + will return allocated memory and that DestroyFred() + will deallocate memory. Now, execute cppcheck this way: @@ -487,7 +488,7 @@ void DestroyFred(void *p) { } - By default cppcheck will not detect any problems in that + By default Cppcheck will not detect any problems in that code. To enable the exception safety checking you can use @@ -499,8 +500,8 @@ void DestroyFred(void *p) [fred.cpp:3]: (style) Upon exception there is memory leak: a - If an exception occurs when b is allocated, - a will leak. + If an exception occurs when b is allocated, + a will leak. Here is another example: @@ -528,17 +529,18 @@ int a(int sz) 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. + (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: - htmlreport/cppcheck-htmlreport -h + htmlreport/cppcheck-htmlreport -h The output screen says: - Usage: cppcheck-htmlreport [options] + Usage: cppcheck-htmlreport [options] Options: -h, --help show this help message and exit @@ -547,7 +549,7 @@ Options: --report-dir=REPORT_DIR The directory where the html report content is written. --source-dir=SOURCE_DIR - Base directory where source code files can be found. + Base directory where source code files can be found. An example usage: diff --git a/man/writing-rules-1.docbook b/man/writing-rules-1.docbook index 0de22f83d..3168b1195 100644 --- a/man/writing-rules-1.docbook +++ b/man/writing-rules-1.docbook @@ -39,7 +39,8 @@ you write rules. Between each token in the code there is always a space. For instance - the raw code "1+f()" is processed into "1 + f ( )". + the raw code "1+f()" is processed into "1 + f ( )" + . The code is simplified in many ways. @@ -62,10 +63,10 @@
Step 1 - Creating the regular expression - Cppcheck uses the PCRE library to handle - regular expressions. PCRE stands for "Perl Compatible - Regular Expressions". The homepage for PCRE is - http://www.pcre.org. + Cppcheck uses the PCRE library to handle regular expressions. + PCRE stands for "Perl Compatible Regular Expressions". + The homepage for PCRE is + http://www.pcre.org/. Let's create a regular expression that checks for code such as: @@ -74,7 +75,8 @@ free(p); For such code the condition is often redundant (on most - implementations it is valid to free a NULL pointer). + implementations it is valid to free a NULL pointer). + The regular expression must be written for the simplified code. To see what the simplified code looks like you can create a source file diff --git a/man/writing-rules-2.docbook b/man/writing-rules-2.docbook index 27f97c380..71e1714d3 100644 --- a/man/writing-rules-2.docbook +++ b/man/writing-rules-2.docbook @@ -256,7 +256,7 @@ s8 x; } } - The x=f1() is broken out. The + The x=f1() is broken out. The --debug output: 1: void f ( )