CheckMemoryLeak: Fix FP when overloaded new is used

This commit is contained in:
Daniel Marjamäki 2016-01-20 10:34:03 +01:00
parent 4a3ece5847
commit 642cc57428
2 changed files with 3 additions and 0 deletions

View File

@ -123,6 +123,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
return Malloc;
if (tokenizer->isCPP() && tok2->str() == "new") {
if (tok2->strAt(1) == "(" && !Token::Match(tok2->next(),"( std| ::| nothrow )"))
return No;
if (tok2->astOperand1() && (tok2->astOperand1()->str() == "[" || (tok2->astOperand1()->astOperand1() && tok2->astOperand1()->astOperand1()->str() == "[")))
return NewArray;
return New;

View File

@ -410,6 +410,7 @@ private:
ASSERT_EQUALS(";;alloc;", getcode("int **a = new int*[10];", "a"));
ASSERT_EQUALS(";;alloc;", getcode("int * const a = new int[10];", "a"));
ASSERT_EQUALS(";;alloc;", getcode("const int * const a = new int[10];", "a"));
ASSERT_EQUALS(";;assign;", getcode("A * a = new (X) A;", "a"));
ASSERT_EQUALS(";;alloc;", getcode("int i = open(a,b);", "i"));
ASSERT_EQUALS(";;assign;", getcode("int i = open();", "i"));