Fixed #4735 (FP: Mismatching assignment and comparison)

This commit is contained in:
Daniel Marjamäki 2013-04-23 06:47:15 +02:00
parent a5b044a6e2
commit e1dd14626c
2 changed files with 14 additions and 2 deletions

View File

@ -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());

View File

@ -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() {