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