Null pointers: Fixed false positive when sizeof without parentheses are used

This commit is contained in:
Daniel Marjamäki 2011-12-17 12:44:11 +01:00
parent 4abee3a345
commit e008a0508b
2 changed files with 11 additions and 1 deletions

View File

@ -896,7 +896,10 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
} }
// parameters to sizeof are not dereferenced // parameters to sizeof are not dereferenced
if (Token::Match(tok2, "decltype|sizeof (")) { if (Token::Match(tok2, "decltype|sizeof")) {
if (tok2->strAt(1) != "(")
break;
tok2 = tok2->next()->link(); tok2 = tok2->next()->link();
continue; continue;
} }

View File

@ -1434,6 +1434,13 @@ private:
" strcpy(a, s?b:c);\n" " strcpy(a, s?b:c);\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// sizeof
check("void f(struct fred_t *fred) {\n"
" if (!fred)\n"
" int sz = sizeof fred->x;\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
// Test CheckNullPointer::nullConstantDereference // Test CheckNullPointer::nullConstantDereference