Fixed #1654 (False positive: Memory leak with: ( delete ( p ) , ( p ) = 0 );)
This commit is contained in:
parent
21b7eb61f5
commit
d19dd2c61d
|
@ -5275,6 +5275,14 @@ bool Tokenizer::simplifyRedundantParanthesis()
|
|||
ret = true;
|
||||
}
|
||||
|
||||
if ((Token::simpleMatch(tok->previous(), "delete (") && Token::Match(tok->link(), ") ;|,")) ||
|
||||
(Token::simpleMatch(tok->previous(), "; (") && Token::Match(tok->link(), ") ;")))
|
||||
{
|
||||
tok->link()->deleteThis();
|
||||
tok->deleteThis();
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if (Token::Match(tok->previous(), "[(!*;{}] ( %var% )") && tok->next()->varId() != 0)
|
||||
{
|
||||
// We have "( var )", remove the paranthesis
|
||||
|
|
|
@ -157,6 +157,7 @@ private:
|
|||
TEST_CASE(removeParantheses4); // Ticket #390
|
||||
TEST_CASE(removeParantheses5); // Ticket #392
|
||||
TEST_CASE(removeParantheses6);
|
||||
TEST_CASE(removeParantheses7);
|
||||
|
||||
TEST_CASE(tokenize_double);
|
||||
TEST_CASE(tokenize_strings);
|
||||
|
@ -2475,6 +2476,23 @@ private:
|
|||
ASSERT_EQUALS(" ( ! abc . a )", ostr.str());
|
||||
}
|
||||
|
||||
void removeParantheses7()
|
||||
{
|
||||
const char code[] = ";(delete(p), (p)=0);";
|
||||
|
||||
// tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
std::ostringstream ostr;
|
||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
ostr << " " << tok->str();
|
||||
ASSERT_EQUALS(" ; delete p ; ( p ) = 0 ;", ostr.str());
|
||||
}
|
||||
|
||||
void tokenize_double()
|
||||
{
|
||||
const char code[] = "void f()\n"
|
||||
|
|
Loading…
Reference in New Issue