Skip to content

Commit 5c07299

Browse files
committed
CheckBool: Fixed false negative when assigning bool to pointer '; s.p = true; '
1 parent b577b12 commit 5c07299

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/checkbool.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,13 @@ void CheckBool::checkAssignBoolToPointer()
333333
const Scope * scope = symbolDatabase->functionScopes[i];
334334
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
335335
if (Token::Match(tok, "%var% = %bool% ;")) {
336-
// Todo: properly check if there is a deref
336+
// check if there is a deref
337337
// *x.p = true; // <- don't warn
338338
// x.p = true; // <- warn
339-
if (Token::Match(tok->previous(), "[*.)]"))
339+
const Token *prev = tok;
340+
while (Token::Match(prev->tokAt(-2), "%var% ."))
341+
prev = prev->tokAt(-2);
342+
if (Token::Match(prev->previous(), "[*.)]"))
340343
continue;
341344

342345
// Is variable a pointer?

test/testbool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class TestBool : public TestFixture {
111111
" S s = {0};\n"
112112
" s.p = true;\n"
113113
"}\n");
114-
TODO_ASSERT_EQUALS("error", "", errout.str());
114+
ASSERT_EQUALS("[test.cpp:6]: (error) Boolean value assigned to pointer.\n", errout.str());
115115
}
116116

117117
void comparisonOfBoolExpressionWithInt1() {

0 commit comments

Comments
 (0)