Uninitialized variables; Fixed false positive in sizeof()

This commit is contained in:
Daniel Marjamäki 2021-05-22 11:04:42 +02:00
parent f5f3a8d4d7
commit 1cb48ad418
2 changed files with 12 additions and 0 deletions

View File

@ -809,6 +809,9 @@ const Token *CheckUninitVar::checkExpr(const Token *tok, const Variable& var, co
{
if (!tok)
return nullptr;
if (Token::Match(tok->previous(), "sizeof|typeof|offsetof|decltype ("))
return nullptr;
if (tok->astOperand1()) {
bool bailout1 = false;
const Token *errorToken = checkExpr(tok->astOperand1(), var, alloc, known, &bailout1);

View File

@ -80,6 +80,7 @@ private:
TEST_CASE(uninitvar_cpp11ArrayInit); // #7010
TEST_CASE(uninitvar_rangeBasedFor); // #7078
TEST_CASE(uninitvar_static); // #8734
TEST_CASE(checkExpr);
TEST_CASE(trac_4871);
TEST_CASE(syntax_error); // Ticket #5073
TEST_CASE(trac_5970);
@ -4237,6 +4238,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void checkExpr() {
checkUninitVar("struct AB { int a; int b; };\n"
"void f() {\n"
" struct AB *ab = (struct AB*)calloc(1, sizeof(*ab));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void trac_4871() { // #4871
checkUninitVar("void pickup(int a) {\n"
"bool using_planner_action;\n"