Fixed #4735 (FP: Mismatching assignment and comparison)
This commit is contained in:
parent
a5b044a6e2
commit
e1dd14626c
|
@ -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());
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue