Uninitialized variables: fixed false positive in while loop
This commit is contained in:
parent
6b01d2d5a8
commit
6997d38881
|
@ -1503,14 +1503,16 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
|
|||
} else {
|
||||
if (isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP()))
|
||||
usetok = tok;
|
||||
else if (tok->strAt(1) == "=") {
|
||||
else {
|
||||
bool assign = true;
|
||||
if (tok->strAt(1) == "=") {
|
||||
for (const Token *tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
|
||||
if (tok2->varId() == var.varId()) {
|
||||
assign = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (assign)
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2842,6 +2842,15 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int x;\n"
|
||||
" while (a) {\n"
|
||||
" init(&x);\n"
|
||||
" x++;\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int x;\n"
|
||||
" while (a) {\n"
|
||||
|
|
Loading…
Reference in New Issue