Skip to content

Commit

Permalink
Fix #13360 FN comparisonError with bit mask (regression) (danmar#7051)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 5, 2024
1 parent 4a0da3a commit 94218bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,13 @@ void CheckCondition::comparison()
const Token *expr2 = tok->astOperand2();
if (!expr1 || !expr2)
continue;
if (expr1->isNumber())
if (expr1->hasKnownIntValue())
std::swap(expr1,expr2);
if (!expr2->isNumber())
if (!expr2->hasKnownIntValue())
continue;
if (!compareTokenFlags(expr1, expr2, /*macro*/ true))
continue;
const MathLib::bigint num2 = MathLib::toBigNumber(expr2->str());
const MathLib::bigint num2 = expr2->getKnownIntValue();
if (num2 < 0)
continue;
if (!Token::Match(expr1,"[&|]"))
Expand Down
9 changes: 9 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@ class TestCondition : public TestFixture {
" if (MACRO_ALL == 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());

checkP("void f(int i, int j) {\n" // #13360
" int X = 0x10;\n"
" if ((i & 0xff00) == X) {}\n"
" if (X == (j & 0xff00)) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0xff00) == 0x10' is always false.\n"
"[test.cpp:4]: (style) Expression '(X & 0xff00) == 0x10' is always false.\n",
errout_str());
}

#define checkPureFunction(code) checkPureFunction_(code, __FILE__, __LINE__)
Expand Down

0 comments on commit 94218bd

Please sign in to comment.