Fixed broken AST for simple expressions with delete operator.
Fixed cppcheck internal warning
This commit is contained in:
parent
4957e48d7c
commit
1566b72c5b
|
@ -232,8 +232,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
|
||||||
|
|
||||||
CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok, unsigned int varid) const
|
CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok, unsigned int varid) const
|
||||||
{
|
{
|
||||||
if (tokenizer->isCPP() && tok->str() == "delete") {
|
if (tokenizer->isCPP() && tok->str() == "delete" && tok->astOperand1()) {
|
||||||
const Token* vartok = tok->astOperand1() ? tok->astOperand1() : tok->next();
|
const Token* vartok = tok->astOperand1();
|
||||||
if (Token::Match(vartok, ".|::"))
|
if (Token::Match(vartok, ".|::"))
|
||||||
vartok = vartok->astOperand2();
|
vartok = vartok->astOperand2();
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
|
||||||
|
|
||||||
if (Token::Match(vartok, "%varid% )|,|-", varid)) {
|
if (Token::Match(vartok, "%varid% )|,|-", varid)) {
|
||||||
if (Token::Match(tok, "free|kfree") ||
|
if (Token::Match(tok, "free|kfree") ||
|
||||||
(tok->str() == "realloc" && Token::Match(vartok->next(), ", 0 )")))
|
(tok->str() == "realloc" && Token::simpleMatch(vartok->next(), ", 0 )")))
|
||||||
return Malloc;
|
return Malloc;
|
||||||
|
|
||||||
if (tok->str() == "fclose")
|
if (tok->str() == "fclose")
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
||||||
if (Token::Match(tok, "%type% <") && !Token::Match(tok->linkAt(1), "> [({]"))
|
if (Token::Match(tok, "%type% <") && !Token::Match(tok->linkAt(1), "> [({]"))
|
||||||
return 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%"))
|
if (cpp && Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%"))
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
|
|
||||||
|
|
|
@ -8170,6 +8170,7 @@ private:
|
||||||
ASSERT_EQUALS("a::new=", testAst("a = new (b) ::X;"));
|
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("aA1(new(bB2(new(,", testAst("a(new A(1)), b(new B(2))"));
|
||||||
ASSERT_EQUALS("Fred10[new", testAst(";new Fred[10];"));
|
ASSERT_EQUALS("Fred10[new", testAst(";new Fred[10];"));
|
||||||
|
ASSERT_EQUALS("f( adelete", testAst("void f() { delete a; }"));
|
||||||
|
|
||||||
// invalid code (libreoffice), don't hang
|
// invalid code (libreoffice), don't hang
|
||||||
// #define SlideSorterViewShell
|
// #define SlideSorterViewShell
|
||||||
|
|
Loading…
Reference in New Issue