Skip to content

Commit 6031bed

Browse files
authored
Fix 11669: Assert failure in infer.cpp (#4982)
* Fix 11669: Assert failure in infer.cpp * Format
1 parent 4183336 commit 6031bed

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/infer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct Interval {
148148
result.setMinValue(minValue->intvalue + 1, minValue);
149149
if (minValue->isPossible() && minValue->bound == ValueFlow::Value::Bound::Lower)
150150
result.setMinValue(minValue->intvalue, minValue);
151-
if (!minValue->isImpossible() && minValue->bound == ValueFlow::Value::Bound::Point &&
151+
if (!minValue->isImpossible() && (minValue->bound == ValueFlow::Value::Bound::Point || minValue->isKnown()) &&
152152
std::count_if(values.begin(), values.end(), predicate) == 1)
153153
return Interval::fromInt(minValue->intvalue, minValue);
154154
}

test/testvalueflow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7183,6 +7183,17 @@ class TestValueFlow : public TestFixture {
71837183
" a;\n"
71847184
"}\n";
71857185
valueOfTok(code, "a");
7186+
7187+
code = "void f(int i, int j, int n) {\n"
7188+
" if ((j == 0) != (i == 0)) {}\n"
7189+
" int t = 0;\n"
7190+
" if (j > 0) {\n"
7191+
" t = 1;\n"
7192+
" if (n < j)\n"
7193+
" n = j;\n"
7194+
" }\n"
7195+
"}\n";
7196+
valueOfTok(code, "i");
71867197
}
71877198

71887199
void valueFlowCrashConstructorInitialization() { // #9577

0 commit comments

Comments
 (0)