diff --git a/lib/checkassignif.cpp b/lib/checkassignif.cpp index d660aacde..5195e16ff 100644 --- a/lib/checkassignif.cpp +++ b/lib/checkassignif.cpp @@ -52,7 +52,12 @@ void CheckAssignIf::assignIf() bitop = tok->strAt(2).at(0); num = MathLib::toLongNumber(tok->next()->str()); } else { - const Token * const endToken = Token::findsimplematch(tok, ";"); + const Token *endToken = Token::findsimplematch(tok, ";"); + + // Casting address + if (Token::Match(endToken->tokAt(-4), "* ) & %any% ;")) + endToken = NULL; + if (endToken && Token::Match(endToken->tokAt(-2), "[&|] %num% ;")) { bitop = endToken->strAt(-2).at(0); num = MathLib::toLongNumber(endToken->previous()->str()); diff --git a/test/testassignif.cpp b/test/testassignif.cpp index 8d325e9dc..1c1f48270 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -34,7 +34,7 @@ private: void run() { TEST_CASE(assignAndCompare); // assignment and comparison don't match - TEST_CASE(mismatchingBitAnd); // overlapping bitmasks + TEST_CASE(mismatchingBitAnd); // overlapping bitmasks TEST_CASE(compare); // mismatching LHS/RHS in comparison TEST_CASE(multicompare); // mismatching comparisons } @@ -173,6 +173,13 @@ private: " if(x != -1) { }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #4735 + check("void f() {\n" + " int x = *(char*)&0x12345678;\n" + " if (x==18) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void mismatchingBitAnd() {