Skip to content

Commit b469da1

Browse files
authored
Fix issue 8253: False negative: Comparison is always true (early return) (#3043)
1 parent 1858465 commit b469da1

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/forwardanalyzer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,6 @@ struct ForwardTraversal {
386386
Token* endBlock = endCond->next()->link();
387387
Token* condTok = getCondTok(tok);
388388
Token* initTok = getInitTok(tok);
389-
if (!condTok)
390-
return Progress::Break;
391389
if (initTok && updateRecursive(initTok) == Progress::Break)
392390
return Progress::Break;
393391
if (Token::Match(tok, "for|while (")) {

test/testvalueflow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4270,6 +4270,16 @@ class TestValueFlow : public TestFixture {
42704270
"}\n";
42714271
ASSERT_EQUALS(false, testValueOfXKnown(code, 10U, 0));
42724272
ASSERT_EQUALS(false, testValueOfXKnown(code, 10U, 1));
4273+
4274+
code = "void f() {\n"
4275+
" const int size = arrayInfo.num(0);\n"
4276+
" if (size <= 0)\n"
4277+
" return;\n"
4278+
" for (;;)\n"
4279+
" if (size > 0) {}\n"
4280+
"}\n";
4281+
ASSERT_EQUALS(true, valueOfTok(code, "> 0").isKnown());
4282+
ASSERT_EQUALS(true, valueOfTok(code, "> 0").intvalue == 1);
42734283
}
42744284

42754285
static std::string isPossibleContainerSizeValue(const std::list<ValueFlow::Value> &values, MathLib::bigint i) {

0 commit comments

Comments
 (0)