Uninitialized variables: Fixed FP when the variable is initialized in do-while condition
This commit is contained in:
parent
abdd29fce3
commit
7fe923bfc5
|
@ -1395,9 +1395,10 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
return true;
|
||||
|
||||
// is variable used in for-head?
|
||||
bool initcond = false;
|
||||
if (!suppressErrors) {
|
||||
const Token *startCond = forwhile ? tok->next() : tok->next()->link()->tokAt(2);
|
||||
checkIfForWhileHead(startCond, var, false, bool(number_of_if == 0), alloc && *alloc, membervar);
|
||||
initcond = checkIfForWhileHead(startCond, var, false, bool(number_of_if == 0), alloc && *alloc, membervar);
|
||||
}
|
||||
|
||||
// goto "}"
|
||||
|
@ -1418,6 +1419,10 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
if (!tok)
|
||||
// bailout : invalid code / bad tokenizer
|
||||
break;
|
||||
|
||||
if (initcond)
|
||||
// variable is initialized in while-condition
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3106,6 +3106,13 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int i;\n"
|
||||
" do {} while (!getvalue(&i));\n"
|
||||
" i++;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2(">{ x while (y) z int = }"); // #4175 : don't crash
|
||||
|
||||
checkUninitVar2("int f(void) {\n"
|
||||
|
|
Loading…
Reference in New Issue