value flow: Fixed wrong value in subfunction after conditional return

This commit is contained in:
Daniel Marjamäki 2014-01-08 06:04:51 +01:00
parent f79e1b6d87
commit dfee044925
2 changed files with 12 additions and 1 deletions

View File

@ -182,6 +182,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
{
std::list<ValueFlow::Value> argvalues;
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
// passing value(s) to function
if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty())
argvalues = tok->next()->values;
else if (Token::Match(tok, "[(,] %num% [,)]")) {
@ -226,7 +227,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
} else if (tok2->varId() == varid2 || tok2->str() == "{") {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str());
continue;
break;
}
}
}

View File

@ -136,6 +136,16 @@ private:
" if (x==0){}\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 1U, 0));
code = "void f1(int x) {\n"
" if (x == 0) return;\n"
" int y = 1234 / x;\n"
"}\n"
"\n"
"void f2() {\n"
" f1(0);\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
}
};