Fixed #1654 (False positive: Memory leak with: ( delete ( p ) , ( p ) = 0 );)

This commit is contained in:
Daniel Marjamäki 2010-05-07 18:37:50 +02:00
parent 21b7eb61f5
commit d19dd2c61d
2 changed files with 27 additions and 1 deletions

View File

@ -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

View File

@ -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);
@ -186,7 +187,7 @@ private:
// unsigned i; => unsigned int i;
TEST_CASE(unsigned1);
TEST_CASE(unsigned2);
TEST_CASE(unsigned3); // template arguments
TEST_CASE(unsigned3); // template arguments
TEST_CASE(testUpdateClassList);
TEST_CASE(createLinks);
@ -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"