ValueFlow: Better handling of calculated function arguments in valueFlowSubFunction
This commit is contained in:
parent
344016f7ab
commit
d35ce5f0db
|
@ -1327,11 +1327,9 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// passing value(s) to function
|
// passing value(s) to function
|
||||||
if (Token::Match(tok, "[(,] %var% [,)]") && !tok->next()->values.empty())
|
if (Token::Match(tok, "[(,] %var%|%num%|%str% [,)]") && !tok->next()->values.empty())
|
||||||
argvalues = tok->next()->values;
|
argvalues = tok->next()->values;
|
||||||
else if (Token::Match(tok, "[(,] %num%|%str% [,)]") && !tok->next()->values.empty()) {
|
else {
|
||||||
argvalues = tok->next()->values;
|
|
||||||
} else {
|
|
||||||
// bool operator => values 1/0 are passed to function..
|
// bool operator => values 1/0 are passed to function..
|
||||||
const Token *op = tok->next();
|
const Token *op = tok->next();
|
||||||
while (op && op->astParent() && !Token::Match(op->astParent(), "[(,]"))
|
while (op && op->astParent() && !Token::Match(op->astParent(), "[(,]"))
|
||||||
|
@ -1340,6 +1338,8 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
|
||||||
argvalues.clear();
|
argvalues.clear();
|
||||||
argvalues.push_back(ValueFlow::Value(0));
|
argvalues.push_back(ValueFlow::Value(0));
|
||||||
argvalues.push_back(ValueFlow::Value(1));
|
argvalues.push_back(ValueFlow::Value(1));
|
||||||
|
} else if (Token::Match(op, "%cop%") && !op->values.empty()) {
|
||||||
|
argvalues = op->values;
|
||||||
} else {
|
} else {
|
||||||
// possible values are unknown..
|
// possible values are unknown..
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1096,6 +1096,16 @@ private:
|
||||||
"}\n"
|
"}\n"
|
||||||
"void f2() { f1(0.5); }";
|
"void f2() { f1(0.5); }";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 2U, 0));
|
ASSERT_EQUALS(false, testValueOfX(code, 2U, 0));
|
||||||
|
|
||||||
|
code = "void dostuff(int x) {\n"
|
||||||
|
" return x/x;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void test(int x) {\n"
|
||||||
|
" if(x==1) {}\n"
|
||||||
|
" dostuff(x+1);\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 2U, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowFunctionReturn() {
|
void valueFlowFunctionReturn() {
|
||||||
|
|
Loading…
Reference in New Issue