Fixed #5937 (ValueFlow: wrong analysis of calculations with different variable operands)

This commit is contained in:
Daniel Marjamäki 2014-06-29 10:57:39 +02:00
parent 1bcb22e4a4
commit 893996d182
2 changed files with 18 additions and 0 deletions

View File

@ -245,6 +245,8 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
tok->values.push_back(value);
it = tok->values.end();
--it;
if (it->varId == 0)
it->varId = tok->varId();
}
Token *parent = const_cast<Token*>(tok->astParent());

View File

@ -169,6 +169,22 @@ private:
" f(7);\n"
"}";
ASSERT_EQUALS(15, valueOfTok(code, "+").intvalue);
code = "void f(int x, int y) {\n"
" a = x + y;\n"
"}\n"
"void callf() {\n"
" f(1,1);\n"
" f(10,10);\n"
"}";
values = tokenValues(code, "+");
ASSERT_EQUALS(true, values.empty());
if (!values.empty()) {
/* todo.. */
ASSERT_EQUALS(2U, values.size());
ASSERT_EQUALS(2, values.front().intvalue);
ASSERT_EQUALS(22, values.back().intvalue);
}
}
void valueFlowBeforeCondition() {