Fixed #925 (uninitialized deletion not detected)

This commit is contained in:
Daniel Marjamäki 2009-11-15 20:01:57 +01:00
parent 95c898f37b
commit 469a8e4032
2 changed files with 20 additions and 0 deletions

View File

@ -1317,6 +1317,12 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
return 0; return 0;
} }
} }
if (Token::simpleMatch(tok->previous(), "delete") ||
Token::simpleMatch(tok->tokAt(-3), "delete [ ]"))
{
return tok;
}
} }
if (Token::Match(tok, "%var% (")) if (Token::Match(tok, "%var% ("))

View File

@ -959,6 +959,20 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" int *p;\n"
" delete p;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" int *p;\n"
" delete [] p;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("static void foo()\n" checkUninitVar("static void foo()\n"
"{\n" "{\n"
" Foo p;\n" " Foo p;\n"