Uninitialized variables: Fixed false positives when sizeof is used in condition. Ticket: #3369

This commit is contained in:
Daniel Marjamäki 2011-12-17 16:08:55 +01:00
parent 322f46c761
commit f09a5b408b
2 changed files with 9 additions and 1 deletions

View File

@ -1089,6 +1089,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
uninitvarError(tok2, tok2->str());
return true;
}
if (Token::Match(tok2, "sizeof|decltype|offsetof ("))
tok2 = tok2->next()->link();
}
// goto the {
@ -1141,7 +1143,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
}
// skip sizeof / offsetof
if (Token::Match(tok, "sizeof|offsetof ("))
if (Token::Match(tok, "sizeof|offsetof|decltype ("))
tok = tok->next()->link();
// TODO: handle loops, try, etc

View File

@ -1880,6 +1880,12 @@ private:
" sizeof(i+1);\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" int i;\n"
" if (100 == sizeof(i+1));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};