Fixed #915 (false positive: memory leak for struct member (allocated in condition)

This commit is contained in:
Daniel Marjamäki 2009-11-15 09:28:08 +01:00
parent ebf907cbc0
commit 5dd7b054f9
2 changed files with 29 additions and 2 deletions

View File

@ -3635,9 +3635,17 @@ bool Tokenizer::simplifyRedundantParanthesis()
if (Token::Match(tok->previous(), "[(!*;}] ( %var% )") && tok->next()->varId() != 0)
{
// We have "( var )", remove the paranthesis
tok = tok->previous();
tok->deleteThis();
tok->deleteNext();
tok = tok->next();
ret = true;
continue;
}
if (Token::Match(tok->previous(), "[(!] ( %var% . %var% )"))
{
// We have "( var . var )", remove the paranthesis
tok->deleteThis();
tok = tok->tokAt(2);
tok->deleteNext();
ret = true;
continue;

View File

@ -130,6 +130,7 @@ private:
TEST_CASE(removeParantheses3);
TEST_CASE(removeParantheses4); // Ticket #390
TEST_CASE(removeParantheses5); // Ticket #392
TEST_CASE(removeParantheses6);
TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings);
@ -2055,6 +2056,24 @@ private:
}
}
// "!(abc.a)" => "!abc.a"
void removeParantheses6()
{
const char code[] = "(!(abc.a))";
// 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(" ( ! abc . a )", ostr.str());
}
void tokenize_double()
{
const char code[] = "void f()\n"