Skip to content

Commit

Permalink
Fix #13222 FP comparisonError with nested defines (#6919)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Oct 16, 2024
1 parent 2844f8e commit 4da801e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ void CheckCondition::comparison()
std::swap(expr1,expr2);
if (!expr2->isNumber())
continue;
if (!compareTokenFlags(expr1, expr2, /*macro*/ true))
continue;
const MathLib::bigint num2 = MathLib::toBigNumber(expr2->str());
if (num2 < 0)
continue;
Expand Down
8 changes: 8 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@ class TestCondition : public TestFixture {
"[test.cpp:2]: (style) Expression '(X & 0x100) == 0x200' is always false.\n"
"[test.cpp:3]: (style) Expression '(X & 0x100) == 0x200' is always false.\n",
errout_str());

checkP("#define MACRO1 (0x0010)\n" // #13222
"#define MACRO2 (0x0020)\n"
"#define MACRO_ALL (MACRO1 | MACRO2)\n"
"void f() {\n"
" if (MACRO_ALL == 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

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

0 comments on commit 4da801e

Please sign in to comment.