Fixed #5559 (false positive: (error) Possible null pointer dereference: pSTRunner)

This commit is contained in:
Daniel Marjamäki 2014-04-26 11:27:58 +02:00
parent 806daf7644
commit 853d56030b
2 changed files with 18 additions and 1 deletions

View File

@ -531,6 +531,7 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
int indentlevel = 0;
unsigned int number_of_if = 0;
int varusagelevel = -1;
bool returnStatement = false; // current statement is a return, stop analysis at the ";"
for (Token *tok2 = tok; tok2 && tok2 != endToken; tok2 = tok2->next()) {
if (indentlevel >= 0 && tok2->str() == "{")
@ -611,12 +612,18 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
tok2 = tok2->linkAt(2);
}
else if (Token::Match(tok2, "break|continue")) {
else if (indentlevel <= 0 && Token::Match(tok2, "break|continue")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + ". noreturn conditional scope.");
break;
}
else if (indentlevel <= 0 && tok2->str() == "return")
returnStatement = true;
else if (returnStatement && tok2->str() == ";")
break;
if (tok2->varId() == varid) {
// bailout: assignment
if (Token::Match(tok2->previous(), "!!* %var% =")) {

View File

@ -613,6 +613,16 @@ private:
"}";
ASSERT_EQUALS(false, testValueOfX(code, 6U, 0));
code = "void f () {\n"
" ST * x = g_pST;\n"
" if (x->y == 0) {\n"
" x = NULL;\n"
" return 1;\n"
" }\n"
" a = x->y;\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 7U, 0));
// multivariables
code = "void f(int a) {\n"
" int x = a;\n"