Fixed #7175 (False positive performance warning (buffer overwritten before its old content has been used))
This commit is contained in:
parent
1f858e955f
commit
d1f06ff47c
|
@ -573,6 +573,19 @@ void CheckOther::checkRedundantAssignment()
|
||||||
if (it == memAssignments.end())
|
if (it == memAssignments.end())
|
||||||
memAssignments[param1->varId()] = tok;
|
memAssignments[param1->varId()] = tok;
|
||||||
else {
|
else {
|
||||||
|
bool read = false;
|
||||||
|
for (const Token *tok2 = tok->linkAt(1); tok2 != writtenArgumentsEnd; tok2 = tok2->previous()) {
|
||||||
|
if (tok2->varId() == param1->varId()) {
|
||||||
|
// TODO: is this a read? maybe it's a write
|
||||||
|
read = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (read) {
|
||||||
|
memAssignments[param1->varId()] = tok;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (printWarning && scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok))
|
if (printWarning && scope->type == Scope::eSwitch && Token::findmatch(it->second, "default|case", tok))
|
||||||
redundantCopyInSwitchError(it->second, tok, param1->str());
|
redundantCopyInSwitchError(it->second, tok, param1->str());
|
||||||
else if (printPerformance)
|
else if (printPerformance)
|
||||||
|
|
|
@ -5389,6 +5389,23 @@ private:
|
||||||
" return i;\n"
|
" return i;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #7175 - read+write
|
||||||
|
check("void f() {\n"
|
||||||
|
" char buf[100];\n"
|
||||||
|
" strcpy(buf, x);\n"
|
||||||
|
" strcpy(buf, dostuff(buf));\n" // <- read + write
|
||||||
|
" strcpy(buf, x);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" char buf[100];\n"
|
||||||
|
" strcpy(buf, x);\n"
|
||||||
|
" strcpy(buf, dostuff(buf));\n"
|
||||||
|
" strcpy(buf, x);\n"
|
||||||
|
"}");
|
||||||
|
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void varFuncNullUB() { // #4482
|
void varFuncNullUB() { // #4482
|
||||||
|
|
Loading…
Reference in New Issue