Skip to content

Commit 747e257

Browse files
Fix #14716 FP oppositeInnerCondition, x.size() < y.size() does not mean that x must be empty (#8533)
1 parent ce9227f commit 747e257

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ static bool isZeroBoundCond(const Token * const cond, bool reverse)
18161816

18171817
const Token* op = reverse ? cond->astOperand1() : cond->astOperand2();
18181818
if (!op->hasKnownIntValue())
1819-
return false;
1819+
return true;
18201820

18211821
// Assume unsigned
18221822
const bool isZero = op->getKnownIntValue() == 0;

test/testcondition.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,12 @@ class TestCondition : public TestFixture {
26822682
check("void f1(const std::string &s) { if(s.empty()) if(42 < s.size()) {}}");
26832683
ASSERT_EQUALS("[test.cpp:1:43] -> [test.cpp:1:53]: (warning) Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]\n", errout_str());
26842684

2685+
check("void f(const std::string& s, int n) {\n" // #14716
2686+
" if (s.size() < n)\n"
2687+
" if (s.empty()) {}\n"
2688+
"}");
2689+
ASSERT_EQUALS("", errout_str());
2690+
26852691
// TODO: These are identical condition since size cannot be negative
26862692
check("void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}");
26872693
ASSERT_EQUALS("", errout_str());

0 commit comments

Comments
 (0)