Fixed #6583 (False positive uninitvar - exit() ignored?!)
This commit is contained in:
parent
105de8e917
commit
d563bd73f4
|
@ -1325,7 +1325,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
|||
|
||||
bool possibleInitElse(number_of_if > 0 || suppressErrors);
|
||||
bool noreturnElse = false;
|
||||
const bool initelse = !alwaysTrue && checkScopeForVariable(tok->next(), var, &possibleInitElse, nullptr, alloc, membervar);
|
||||
const bool initelse = !alwaysTrue && checkScopeForVariable(tok->next(), var, &possibleInitElse, &noreturnElse, alloc, membervar);
|
||||
|
||||
std::map<unsigned int, int> varValueElse;
|
||||
if (!alwaysTrue && !initelse && !noreturnElse) {
|
||||
|
@ -1347,14 +1347,15 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
|||
(alwaysTrue || initelse || noreturnElse))
|
||||
return true;
|
||||
|
||||
if ((initif || initelse || possibleInitElse) && !noreturnIf && !noreturnElse) {
|
||||
if (initif || initelse || possibleInitElse)
|
||||
++number_of_if;
|
||||
if (!initif && !noreturnIf)
|
||||
variableValue.insert(varValueIf.begin(), varValueIf.end());
|
||||
if (!initelse && !noreturnElse)
|
||||
variableValue.insert(varValueElse.begin(), varValueElse.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// = { .. }
|
||||
else if (Token::simpleMatch(tok, "= {")) {
|
||||
|
|
|
@ -2607,6 +2607,15 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVarB("int f(int a) {\n" // #6583
|
||||
" int x;\n"
|
||||
" if (a < 2) exit(1);\n"
|
||||
" else if (a == 2) x = 0;\n"
|
||||
" else exit(2);\n"
|
||||
" return x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVarB("int f(int a) {\n" // #4560
|
||||
" int x = 1, y;\n"
|
||||
" if (a) x = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue