value flow: Fixed wrong value in subfunction after conditional return
This commit is contained in:
parent
f79e1b6d87
commit
dfee044925
|
@ -182,6 +182,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
{
|
{
|
||||||
std::list<ValueFlow::Value> argvalues;
|
std::list<ValueFlow::Value> argvalues;
|
||||||
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
||||||
|
// passing value(s) to function
|
||||||
if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty())
|
if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty())
|
||||||
argvalues = tok->next()->values;
|
argvalues = tok->next()->values;
|
||||||
else if (Token::Match(tok, "[(,] %num% [,)]")) {
|
else if (Token::Match(tok, "[(,] %num% [,)]")) {
|
||||||
|
@ -226,7 +227,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
} else if (tok2->varId() == varid2 || tok2->str() == "{") {
|
} else if (tok2->varId() == varid2 || tok2->str() == "{") {
|
||||||
if (settings->debugwarnings)
|
if (settings->debugwarnings)
|
||||||
bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str());
|
bailout(tokenlist, errorLogger, tok2, "parameter " + arg->nameToken()->str());
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,6 +136,16 @@ private:
|
||||||
" if (x==0){}\n"
|
" if (x==0){}\n"
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 1U, 0));
|
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));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue