Fixed ticket #514 (false positive:: memory leak when using comma near delete[])

http://sourceforge.net/apps/trac/cppcheck/ticket/514
This commit is contained in:
Slava Semushin 2009-07-28 02:13:08 +07:00
parent 37fe631639
commit 600f3a834d
2 changed files with 17 additions and 2 deletions

View File

@ -3225,6 +3225,14 @@ bool Tokenizer::simplifyComma()
ret = true;
break;
}
else if (Token::Match(tok2, "delete %var%") ||
Token::Match(tok2, "delete [ ] %var%"))
{
// Handle "delete a, a = 0;"
tok->str(";");
ret = true;
break;
}
else if (Token::Match(tok2, "[;,{}()]"))
{
break;

View File

@ -1076,10 +1076,17 @@ private:
{
const char code[] = "void foo()\n"
"{\n"
" int *a = new int[10];\n"
" delete [] a, a = 0;\n"
"}\n";
TODO_ASSERT_EQUALS(" void foo ( ) { int * a ; a = new int [ 10 ] ; delete [ ] a ; a = 0 ; }", sizeof_(code));
ASSERT_EQUALS(" void foo ( ) { delete [ ] a ; a = 0 ; }", sizeof_(code));
}
{
const char code[] = "void foo()\n"
"{\n"
" delete a, a = 0;\n"
"}\n";
ASSERT_EQUALS(" void foo ( ) { delete a ; a = 0 ; }", sizeof_(code));
}
}