Uninitialized variables: Fixed false positives in sizeof. Ticket: #3369

This commit is contained in:
Daniel Marjamäki 2011-12-17 09:51:45 +01:00
parent dfedb920f8
commit fe8393aafc
2 changed files with 11 additions and 0 deletions

View File

@ -1140,6 +1140,10 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
continue;
}
// skip sizeof / offsetof
if (Token::Match(tok, "sizeof|offsetof ("))
tok = tok->next()->link();
// TODO: handle loops, try, etc
if (tok->str() == "for" || Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) {
return true;

View File

@ -1873,6 +1873,13 @@ private:
" x++;\n"
"}");
ASSERT_EQUALS("", errout.str());
// sizeof / offsetof
checkUninitVar2("void f() {\n"
" int i;\n"
" sizeof(i+1);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};