Skip to content

Commit 98e6dca

Browse files
committed
Ticket danmar#6713: Properly detect ternary operator in valueFlowForward.
1 parent ddc8024 commit 98e6dca

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/valueflow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,8 @@ static bool valueFlowForward(Token * const startToken,
10431043
// If a ? is seen and it's known that the condition is true/false..
10441044
else if (tok2->str() == "?") {
10451045
const Token *condition = tok2->astOperand1();
1046+
if (!condition) // Ticket #6713
1047+
continue;
10461048
std::list<ValueFlow::Value>::const_iterator it;
10471049
for (it = values.begin(); it != values.end(); ++it) {
10481050
const std::map<unsigned int, MathLib::bigint> programMemory(getProgramMemory(tok2, varid, *it));

test/testgarbage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class TestGarbage : public TestFixture {
9494
TEST_CASE(garbageCode53); // #6721
9595
TEST_CASE(garbageCode54); // #6722
9696
TEST_CASE(garbageCode55); // #6724
97+
TEST_CASE(garbageCode56); // #6713
9798

9899
TEST_CASE(garbageValueFlow);
99100
TEST_CASE(garbageSymbolDatabase);
@@ -535,6 +536,10 @@ class TestGarbage : public TestFixture {
535536
checkCode("() __attribute__((constructor)); { } { }");
536537
}
537538

539+
void garbageCode56() { // #6713
540+
checkCode("void foo() { int a = 0; int b = ???; }");
541+
}
542+
538543
void garbageValueFlow() {
539544
// #6089
540545
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"

0 commit comments

Comments
 (0)