Fixed false positive multiCondition when & is used in both conditions (#7827)

This commit is contained in:
PKEuS 2017-03-15 19:37:14 +01:00
parent c638180753
commit ca3e3b3cdb
2 changed files with 14 additions and 0 deletions

View File

@ -385,6 +385,8 @@ bool CheckCondition::isOverlappingCond(const Token * const cond1, const Token *
const MathLib::bigint value1 = MathLib::toLongNumber(num1->str());
const MathLib::bigint value2 = MathLib::toLongNumber(num2->str());
if (cond2->str() == "&")
return ((value1 & value2) == value2);
return ((value1 & value2) > 0);
}
return false;

View File

@ -570,6 +570,18 @@ private:
" else { if (x == sizeof(long double)) {} }"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(int x) {\n"
" if (x & 0x08) {}\n"
" else if (x & 0xF8) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(int x) {\n"
" if (x & 0xF8) {}\n"
" else if (x & 0x08) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
}
void checkBadBitmaskCheck() {