Fixed #6903 (ValueFlow: Fix FP in ?:)

This commit is contained in:
Daniel Marjamäki 2015-09-27 13:29:28 +02:00
parent 0f608b8a66
commit bd243a4748
2 changed files with 13 additions and 2 deletions

View File

@ -253,13 +253,17 @@ static const Token * skipValueInConditionalExpression(const Token * const valuet
while (!tokens.empty()) {
const Token * const tok2 = tokens.top();
tokens.pop();
if (!tok2)
if (!tok2 || tok2->str() == ".")
continue;
if (tok2 != valuetok && tok2->str() == valuetok->str())
// A variable is seen..
if (tok2 != valuetok && tok2->variable() && (tok2->varId() == valuetok->varId() || !tok2->variable()->isArgument())) {
// TODO: limit this bailout
return tok;
}
tokens.push(tok2->astOperand2());
tokens.push(tok2->astOperand1());
}
}
return nullptr;
}

View File

@ -464,6 +464,13 @@ private:
" if (x==0) {}\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
code = "void f(int *x) {\n"
" int a = (x && *x == '1');\n"
" int b = a ? atoi(x) : 0;\n" // <- x is not 0
" if (x==0) {}\n"
"}";
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
}
void valueFlowBeforeConditionFunctionCall() { // function calls