From 8ad33273c800334f5e852749377f644879a3bd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 23 Dec 2013 19:12:06 +0100 Subject: [PATCH] manual: document and --- man/manual.docbook | 71 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/man/manual.docbook b/man/manual.docbook index e52b3b247..8566cfb10 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -5,7 +5,7 @@ Cppcheck 1.63 dev - 2013-07-14 + 2013-12-23 @@ -750,7 +750,7 @@ Checking pen1.c...
- Uninitialized memory + Function argument: Uninitialized memory Here is an example program: @@ -789,7 +789,7 @@ Checking uninit.c...
- Null pointers + Function Argument: Null pointers Cppcheck assumes it's ok to pass NULL pointers to functions. Here is an example program: @@ -825,6 +825,71 @@ Checking null.c... </def>
+
+ Function Argument: Format string + + You can define that a function takes a format string. + Example: + + void test() +{ + do_something("%i %i\n", 1024); +} + + No error is reported for that: + + # cppcheck formatstring.c +Checking formatstring.c... + + A configuration file can be created that says that the string is a + format string. For instance: + + <?xml version="1.0"?> +<def> + <function name="do_something"> + <arg nr="1"> + <formatstr/> + </arg> + </function> +</def>Now Cppcheck will report an error: + + cppcheck --library=test.cfg formatstring.c +Checking formatstring.c... +[formatstring.c:3]: (error) do_something format string requires 2 parameters but only 1 is given. +
+ +
+ Function Argument: Value range + + The valid values can be defined. Imagine: + + void test() +{ + do_something(1024); +} + + No error is reported for that: + + # cppcheck valuerange.c +Checking valuerange.c... + + A configuration file can be created that says that 1024 is out of + bounds. For instance: + + <?xml version="1.0"?> +<def> + <function name="do_something"> + <arg nr="1"> + <valid>0-1023</valid> + </arg> + </function> +</def>Now Cppcheck will report an error: + + 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'. +
+
noreturn