From 798b845ce1c4b701190d34d6793bffca946b0fc9 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 28 Sep 2014 22:20:28 +0200 Subject: [PATCH] Added to manual.docbook --- man/manual.docbook | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/man/manual.docbook b/man/manual.docbook index 4aebf0246..16027a9cf 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -5,7 +5,7 @@ Cppcheck 1.67 dev - 2013-12-23 + 2014-09-28 @@ -846,6 +846,39 @@ Checking noreturn.c... </def> +
+ use-retval + + Per default, cppcheck assumes that ignoring the return value of a function is ok: + + bool test(const char* a, const char* b) +{ + strcmp(a, b); // <- bug: The call of strcmp does not have side-effects, but the return value is ignored. + return true; +} + + In case strcmp has side effects, such as assigning the result to one of the parameters passed to it, nothing bad would happen: + + # cppcheck useretval.c +Checking useretval.c... + + If a proper lib.cfg is provided, the bug is + detected: + + # cppcheck --library=lib.cfg --enable=warning useretval.c +Checking useretval.c... +[noreturn.c:3]: (warning) Return value of function strcmp() is not used. + + Here is a minimal lib.cfg file: + + <?xml version="1.0"?> +<def> + <function name="strcmp"> + <use-retval/> + </function> +</def> +
+
Example configuration for strcpy()