Uninitialized variables; Fixed false positive in sizeof()
This commit is contained in:
parent
f5f3a8d4d7
commit
1cb48ad418
|
@ -809,6 +809,9 @@ const Token *CheckUninitVar::checkExpr(const Token *tok, const Variable& var, co
|
||||||
{
|
{
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
if (Token::Match(tok->previous(), "sizeof|typeof|offsetof|decltype ("))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
if (tok->astOperand1()) {
|
if (tok->astOperand1()) {
|
||||||
bool bailout1 = false;
|
bool bailout1 = false;
|
||||||
const Token *errorToken = checkExpr(tok->astOperand1(), var, alloc, known, &bailout1);
|
const Token *errorToken = checkExpr(tok->astOperand1(), var, alloc, known, &bailout1);
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
TEST_CASE(uninitvar_cpp11ArrayInit); // #7010
|
TEST_CASE(uninitvar_cpp11ArrayInit); // #7010
|
||||||
TEST_CASE(uninitvar_rangeBasedFor); // #7078
|
TEST_CASE(uninitvar_rangeBasedFor); // #7078
|
||||||
TEST_CASE(uninitvar_static); // #8734
|
TEST_CASE(uninitvar_static); // #8734
|
||||||
|
TEST_CASE(checkExpr);
|
||||||
TEST_CASE(trac_4871);
|
TEST_CASE(trac_4871);
|
||||||
TEST_CASE(syntax_error); // Ticket #5073
|
TEST_CASE(syntax_error); // Ticket #5073
|
||||||
TEST_CASE(trac_5970);
|
TEST_CASE(trac_5970);
|
||||||
|
@ -4237,6 +4238,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
void trac_4871() { // #4871
|
||||||
checkUninitVar("void pickup(int a) {\n"
|
checkUninitVar("void pickup(int a) {\n"
|
||||||
"bool using_planner_action;\n"
|
"bool using_planner_action;\n"
|
||||||
|
|
Loading…
Reference in New Issue