Fixed broken AST for simple expressions with delete operator.

Fixed cppcheck internal warning
This commit is contained in:
PKEuS 2015-11-18 21:37:37 +01:00
parent 4957e48d7c
commit 1566b72c5b
3 changed files with 5 additions and 4 deletions

View File

@ -232,8 +232,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok, unsigned int varid) const
{
if (tokenizer->isCPP() && tok->str() == "delete") {
const Token* vartok = tok->astOperand1() ? tok->astOperand1() : tok->next();
if (tokenizer->isCPP() && tok->str() == "delete" && tok->astOperand1()) {
const Token* vartok = tok->astOperand1();
if (Token::Match(vartok, ".|::"))
vartok = vartok->astOperand2();
@ -257,7 +257,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
if (Token::Match(vartok, "%varid% )|,|-", varid)) {
if (Token::Match(tok, "free|kfree") ||
(tok->str() == "realloc" && Token::Match(vartok->next(), ", 0 )")))
(tok->str() == "realloc" && Token::simpleMatch(vartok->next(), ", 0 )")))
return Malloc;
if (tok->str() == "fclose")

View File

@ -1013,7 +1013,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
if (Token::Match(tok, "%type% <") && !Token::Match(tok->linkAt(1), "> [({]"))
return tok->linkAt(1);
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
if (cpp && Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%"))
tok = tok->previous();

View File

@ -8170,6 +8170,7 @@ private:
ASSERT_EQUALS("a::new=", testAst("a = new (b) ::X;"));
ASSERT_EQUALS("aA1(new(bB2(new(,", testAst("a(new A(1)), b(new B(2))"));
ASSERT_EQUALS("Fred10[new", testAst(";new Fred[10];"));
ASSERT_EQUALS("f( adelete", testAst("void f() { delete a; }"));
// invalid code (libreoffice), don't hang
// #define SlideSorterViewShell