Fixed #4652 (False positive: variable value tracking into loop body)
This commit is contained in:
parent
a861817a01
commit
065853a59a
|
@ -1327,11 +1327,10 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
const Token *tok2 = tok->next()->link()->next();
|
||||
|
||||
if (tok2 && tok2->str() == "{") {
|
||||
bool possibleinit = false;
|
||||
bool init = checkLoopBody(tok2, var, membervar, suppressErrors);
|
||||
bool init = checkLoopBody(tok2, var, membervar, (number_of_if > 0) | suppressErrors);
|
||||
|
||||
// variable is initialized in the loop..
|
||||
if (possibleinit || init)
|
||||
if (init)
|
||||
return true;
|
||||
|
||||
// is variable used in for-head?
|
||||
|
|
|
@ -2618,6 +2618,15 @@ private:
|
|||
" i++;\n" // <- no error if b(x) is always true when a(x) is false
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f(int x) {\n"
|
||||
" int i;\n"
|
||||
" if (x) i = 0;\n"
|
||||
" while (condition) {\n"
|
||||
" if (x) i++;\n" // <- no error
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar2_structmembers() { // struct members
|
||||
|
|
Loading…
Reference in New Issue