Fixed #6903 (ValueFlow: Fix FP in ?:)
This commit is contained in:
parent
0f608b8a66
commit
bd243a4748
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue