Uninitialized variables: handle unsimplified labels better
This commit is contained in:
parent
db2a129557
commit
299c1bb208
|
@ -1097,8 +1097,6 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
||||||
if (possibleInit)
|
if (possibleInit)
|
||||||
*possibleInit = false;
|
*possibleInit = false;
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
unsigned int number_of_if = 0;
|
unsigned int number_of_if = 0;
|
||||||
|
|
||||||
// variable values
|
// variable values
|
||||||
|
@ -1292,10 +1290,24 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
||||||
if (Token::Match(tok, "return|break|continue|throw|goto")) {
|
if (Token::Match(tok, "return|break|continue|throw|goto")) {
|
||||||
if (noreturn)
|
if (noreturn)
|
||||||
*noreturn = true;
|
*noreturn = true;
|
||||||
else
|
|
||||||
ret = true;
|
while (tok && tok->str() != ";") {
|
||||||
} else if (tok->str() == "goto")
|
// variable is seen..
|
||||||
return true;
|
if (tok->varId() == var.varId()) {
|
||||||
|
// Use variable
|
||||||
|
if (!suppressErrors && isVariableUsage(scope, tok, var.isPointer()))
|
||||||
|
uninitvarError(tok, tok->str());
|
||||||
|
|
||||||
|
else
|
||||||
|
// assume that variable is assigned
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
return bool(noreturn==NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// variable is seen..
|
// variable is seen..
|
||||||
if (tok->varId() == var.varId()) {
|
if (tok->varId() == var.varId()) {
|
||||||
|
@ -1309,7 +1321,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckUninitVar::checkIfForWhileHead(const Scope *scope, const Token *startparanthesis, const Variable& var, bool suppressErrors, bool isuninit)
|
bool CheckUninitVar::checkIfForWhileHead(const Scope *scope, const Token *startparanthesis, const Variable& var, bool suppressErrors, bool isuninit)
|
||||||
|
|
|
@ -2106,6 +2106,19 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("int f(int x) {\n"
|
||||||
|
" int ret;\n"
|
||||||
|
" if (!x) {\n"
|
||||||
|
" ret = -123;\n"
|
||||||
|
" goto out1;\n"
|
||||||
|
" }\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"out1:\n"
|
||||||
|
"out2:\n"
|
||||||
|
" return ret;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVar2("void f() {\n"
|
checkUninitVar2("void f() {\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" if (x) {\n"
|
" if (x) {\n"
|
||||||
|
|
Loading…
Reference in New Issue