CheckBool: Fixed false negative when assigning bool to pointer '; s.p = true; '

This commit is contained in:
Daniel Marjamäki 2013-10-29 16:16:52 +01:00
parent b577b12660
commit 5c072993e3
2 changed files with 6 additions and 3 deletions

View File

@ -333,10 +333,13 @@ void CheckBool::checkAssignBoolToPointer()
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "%var% = %bool% ;")) {
// Todo: properly check if there is a deref
// check if there is a deref
// *x.p = true; // <- don't warn
// x.p = true; // <- warn
if (Token::Match(tok->previous(), "[*.)]"))
const Token *prev = tok;
while (Token::Match(prev->tokAt(-2), "%var% ."))
prev = prev->tokAt(-2);
if (Token::Match(prev->previous(), "[*.)]"))
continue;
// Is variable a pointer?

View File

@ -111,7 +111,7 @@ private:
" S s = {0};\n"
" s.p = true;\n"
"}\n");
TODO_ASSERT_EQUALS("error", "", errout.str());
ASSERT_EQUALS("[test.cpp:6]: (error) Boolean value assigned to pointer.\n", errout.str());
}
void comparisonOfBoolExpressionWithInt1() {