Uninitialized variables: Fixed false positives in sizeof. Ticket: #3369
This commit is contained in:
parent
dfedb920f8
commit
fe8393aafc
|
@ -1140,6 +1140,10 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skip sizeof / offsetof
|
||||||
|
if (Token::Match(tok, "sizeof|offsetof ("))
|
||||||
|
tok = tok->next()->link();
|
||||||
|
|
||||||
// TODO: handle loops, try, etc
|
// TODO: handle loops, try, etc
|
||||||
if (tok->str() == "for" || Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) {
|
if (tok->str() == "for" || Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1873,6 +1873,13 @@ private:
|
||||||
" x++;\n"
|
" x++;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// sizeof / offsetof
|
||||||
|
checkUninitVar2("void f() {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" sizeof(i+1);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue