Fixed false positive #5689: Care about usage of return values of memory functions
This commit is contained in:
parent
ea23a0467b
commit
866ab1ce14
|
@ -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")) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue