From 866ab1ce148debd1dd4deddc37191795c731ff3f Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 27 Apr 2014 11:00:47 +0200 Subject: [PATCH] Fixed false positive #5689: Care about usage of return values of memory functions --- lib/checkother.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ec841b0e2..9bdb97889 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -776,7 +776,7 @@ void CheckOther::checkRedundantAssignment() if (tok->varId()) // operator() or function pointer varAssignments.erase(tok->varId()); - if (memfunc) { + if (memfunc && tok->strAt(-1) != "(" && tok->strAt(-1) != "=") { const Token* param1 = tok->tokAt(2); writtenArgumentsEnd = param1->next(); if (param1->varId() && param1->strAt(1) == "," && !Token::Match(tok, "strcat|strncat|wcscat|wcsncat")) { diff --git a/test/testother.cpp b/test/testother.cpp index 692fabb23..ce5685319 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6647,6 +6647,14 @@ private: " strcpy(buf, string);\n" "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Buffer 'buf' is being written before its old content has been used.\n", errout.str()); + + // #5689 - use return value of strcpy + check("int f(void* a) {\n" + " int i = atoi(strcpy(a, foo));\n" + " strncpy(a, 0, bar);\n" + " return i;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void varFuncNullUB() { // #4482