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 possibleInitElse(number_of_if > 0 || suppressErrors);
|
||||||
bool noreturnElse = false;
|
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;
|
std::map<unsigned int, int> varValueElse;
|
||||||
if (!alwaysTrue && !initelse && !noreturnElse) {
|
if (!alwaysTrue && !initelse && !noreturnElse) {
|
||||||
|
@ -1347,11 +1347,12 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
(alwaysTrue || initelse || noreturnElse))
|
(alwaysTrue || initelse || noreturnElse))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ((initif || initelse || possibleInitElse) && !noreturnIf && !noreturnElse) {
|
if (initif || initelse || possibleInitElse)
|
||||||
++number_of_if;
|
++number_of_if;
|
||||||
|
if (!initif && !noreturnIf)
|
||||||
variableValue.insert(varValueIf.begin(), varValueIf.end());
|
variableValue.insert(varValueIf.begin(), varValueIf.end());
|
||||||
|
if (!initelse && !noreturnElse)
|
||||||
variableValue.insert(varValueElse.begin(), varValueElse.end());
|
variableValue.insert(varValueElse.begin(), varValueElse.end());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2607,6 +2607,15 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
checkUninitVarB("int f(int a) {\n" // #4560
|
||||||
" int x = 1, y;\n"
|
" int x = 1, y;\n"
|
||||||
" if (a) x = 0;\n"
|
" if (a) x = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue