Fixed #6583 (False positive uninitvar - exit() ignored?!)

This commit is contained in:
Daniel Marjamäki 2015-04-08 15:35:04 +02:00
parent 105de8e917
commit d563bd73f4
2 changed files with 13 additions and 3 deletions

View File

@ -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,11 +1347,12 @@ 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());
}
}
}
}

View File

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