Fixed ticket #390 (wrong allocation and deallocation not detected)

http://sourceforge.net/apps/trac/cppcheck/ticket/390
This commit is contained in:
Slava Semushin 2009-06-12 20:04:58 +07:00
parent 0c01132698
commit 7bee0cd2df
3 changed files with 35 additions and 1 deletions

View File

@ -2569,6 +2569,16 @@ bool Tokenizer::simplifyRedundantParanthesis()
ret = true;
}
while (Token::Match(tok->previous(), "[;{] ( %var% (") &&
tok->link()->previous() == tok->tokAt(2)->link())
{
// We have "( func ( *something* ))", remove the outer
// paranthesis
tok->link()->deleteThis();
tok->deleteThis();
ret = true;
}
if (Token::Match(tok, "( ( %bool% )") ||
Token::Match(tok, "( ( %num% )"))
{

View File

@ -209,7 +209,9 @@ private:
bool simplifyFunctionReturn();
/**
* Remove redundant paranthesis: "((x))" => "(x)"
* Remove redundant paranthesis:
* - "((x))" => "(x)"
* - "(function())" => "function()"
* @return true if modifications to token-list are done.
* false if no modifications are done.
*/

View File

@ -130,6 +130,7 @@ private:
TEST_CASE(removeParantheses1); // Ticket #61
TEST_CASE(removeParantheses2);
TEST_CASE(removeParantheses3);
TEST_CASE(removeParantheses4); // Ticket #390
TEST_CASE(simplify_numeric_condition);
TEST_CASE(tokenize_double);
@ -1726,6 +1727,27 @@ private:
}
}
// Simplify "( function (..))" into "function (..)"
void removeParantheses4()
{
const char code[] = "void foo()\n"
"{\n"
" (free(p));\n"
"}";
// 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(" void foo ( ) { free ( p ) ; }", ostr.str());
}
void simplify_numeric_condition()
{
{