#6543 crash: CheckCondition::checkBadBitmaskCheck ; wine dlls/gdi32/dibdrv/primitives.c. Run astyle.

This commit is contained in:
Alexander Mai 2015-02-23 22:06:55 +01:00
parent fb5cc6fded
commit b9cc5b5c6b
2 changed files with 18 additions and 9 deletions

View File

@ -203,13 +203,13 @@ void CheckCondition::checkBadBitmaskCheck()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (tok->str() == "|" && tok->astOperand1() && tok->astOperand2() && tok->astParent()) {
bool isBoolean = Token::Match(tok->astParent(), "&&|%oror%") ||
(tok->astParent()->str() == "?" && tok->astParent()->astOperand1() == tok) ||
(tok->astParent()->str() == "=" && tok->astParent()->astOperand2() == tok && tok->astParent()->astOperand1()->variable() && tok->astParent()->astOperand1()->variable()->typeStartToken()->str() == "bool") ||
(tok->astParent()->str() == "(" && Token::Match(tok->astParent()->astOperand1(), "if|while"));
const bool isBoolean = Token::Match(tok->astParent(), "&&|%oror%") ||
(tok->astParent()->str() == "?" && tok->astParent()->astOperand1() == tok) ||
(tok->astParent()->str() == "=" && tok->astParent()->astOperand2() == tok && tok->astParent()->astOperand1() && tok->astParent()->astOperand1()->variable() && tok->astParent()->astOperand1()->variable()->typeStartToken()->str() == "bool") ||
(tok->astParent()->str() == "(" && Token::Match(tok->astParent()->astOperand1(), "if|while"));
bool isTrue = (tok->astOperand1()->values.size() == 1 && tok->astOperand1()->values.front().intvalue != 0 && !tok->astOperand1()->values.front().conditional) ||
(tok->astOperand2()->values.size() == 1 && tok->astOperand2()->values.front().intvalue != 0 && !tok->astOperand2()->values.front().conditional);
const bool isTrue = (tok->astOperand1()->values.size() == 1 && tok->astOperand1()->values.front().intvalue != 0 && !tok->astOperand1()->values.front().conditional) ||
(tok->astOperand2()->values.size() == 1 && tok->astOperand2()->values.front().intvalue != 0 && !tok->astOperand2()->values.front().conditional);
if (isBoolean && isTrue)
badBitmaskCheckError(tok);

View File

@ -529,6 +529,15 @@ private:
" return x | 0x02;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void create_rop_masks_4( rop_mask_bits *bits) {\n"
"DWORD mask_offset;\n"
"BYTE *and_bits = bits->and;\n"
"rop_mask *rop_mask;\n"
"and_bits[mask_offset] |= (rop_mask->and & 0x0f);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
@ -1254,7 +1263,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
// clarify conditions with = and comparison
// clarify conditions with = and comparison
void clarifyCondition1() {
check("void f() {\n"
" if (x = b() < 0) {}\n" // don't simplify and verify this code
@ -1277,7 +1286,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
// clarify conditions with bitwise operator and comparison
// clarify conditions with bitwise operator and comparison
void clarifyCondition2() {
check("void f() {\n"
" if (x & 3 == 2) {}\n"
@ -1290,7 +1299,7 @@ private:
ASSERT_EQUALS("[test.cpp:2]: (style) Suspicious condition (bitwise operator + comparison); Clarify expression with parentheses.\n", errout.str());
}
// clarify condition that uses ! operator and then bitwise operator
// clarify condition that uses ! operator and then bitwise operator
void clarifyCondition3() {
check("void f(int w) {\n"
" if(!w & 0x8000) {}\n"