Uninitialized variables: Fixed FP when the variable is initialized in do-while condition

This commit is contained in:
Daniel Marjamäki 2013-12-13 13:27:01 +01:00
parent abdd29fce3
commit 7fe923bfc5
2 changed files with 13 additions and 1 deletions

View File

@ -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;
}
}
}

View File

@ -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"