Fixed ticket #3486 (segmentation fault of cppcheck)
This commit is contained in:
parent
0648b3ed5e
commit
37f3aa1528
|
@ -1120,6 +1120,9 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
// goto the {
|
||||
tok = tok->next()->link()->next();
|
||||
|
||||
if (!tok)
|
||||
break;
|
||||
if (tok->str() == "{") {
|
||||
bool possibleInitIf(number_of_if > 0 || suppressErrors);
|
||||
const bool initif = checkScopeForVariable(tok->next(), varid, ispointer, &possibleInitIf);
|
||||
|
||||
|
@ -1149,6 +1152,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
++number_of_if;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// = { .. }
|
||||
if (Token::simpleMatch(tok, "= {")) {
|
||||
|
@ -1177,6 +1181,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
// goto the {
|
||||
const Token *tok2 = tok->next()->link()->next();
|
||||
|
||||
if (tok2 && tok2->str() == "{") {
|
||||
bool possibleinit = true;
|
||||
bool init = checkScopeForVariable(tok2->next(), varid, ispointer, &possibleinit);
|
||||
|
||||
|
@ -1189,6 +1194,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
checkIfForWhileHead(tok->next(), varid, ispointer, false, bool(number_of_if == 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: handle loops, try, etc
|
||||
if (Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) {
|
||||
|
@ -1206,7 +1212,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
|||
return true;
|
||||
|
||||
// variable is seen..
|
||||
if (tok->varId() == varid) {
|
||||
if (tok && tok->varId() == varid) {
|
||||
// Use variable
|
||||
if (!suppressErrors && isVariableUsage(tok, ispointer))
|
||||
uninitvarError(tok, tok->str());
|
||||
|
|
|
@ -2019,6 +2019,16 @@ private:
|
|||
" typeof(*abc);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #3486 - Don't crash garbage code
|
||||
checkUninitVar2("void f()\n"
|
||||
"{\n"
|
||||
" (\n"
|
||||
" x;\n"
|
||||
" int a, a2, a2*x; if () ;\n"
|
||||
" )\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a2\n", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue