Fixed #1048 (False positive: exceptNew error with nothrow)
This commit is contained in:
parent
d1ebb83884
commit
da4d03f6c4
|
@ -183,7 +183,7 @@ void CheckExceptionSafety::unsafeNew()
|
|||
localVars.insert(tok->varId());
|
||||
}
|
||||
|
||||
if (Token::Match(tok, "; %var% = new"))
|
||||
if (Token::Match(tok, "; %var% = new %type%"))
|
||||
{
|
||||
if (!varname.empty())
|
||||
{
|
||||
|
@ -221,7 +221,7 @@ void CheckExceptionSafety::realloc()
|
|||
break;
|
||||
|
||||
// reallocating..
|
||||
if (!Token::Match(tok, "%var% ; %var% = new"))
|
||||
if (!Token::Match(tok, "%var% ; %var% = new %type%"))
|
||||
continue;
|
||||
|
||||
// variable id of deallocated pointer..
|
||||
|
|
|
@ -90,6 +90,13 @@ private:
|
|||
" A *a2 = new A;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Upon exception there is memory leak: a1\n", errout.str());
|
||||
|
||||
check("void a()\n"
|
||||
"{\n"
|
||||
" A *a1 = new A;\n"
|
||||
" A *a2 = new (std::nothrow) A;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void realloc()
|
||||
|
@ -100,11 +107,22 @@ private:
|
|||
" void a()\n"
|
||||
" {\n"
|
||||
" delete p;\n"
|
||||
" p = new[123];\n"
|
||||
" p = new int[123];\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (style) Upon exception p becomes a dead pointer\n", errout.str());
|
||||
|
||||
check("class A\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
" void a()\n"
|
||||
" {\n"
|
||||
" delete p;\n"
|
||||
" p = new (std::nothrow) int[123];\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class A\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
|
@ -112,7 +130,7 @@ private:
|
|||
" {\n"
|
||||
" try {\n"
|
||||
" delete p;\n"
|
||||
" p = new[123];\n"
|
||||
" p = new int[123];\n"
|
||||
" } catch (...) { p = 0; }\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
|
|
Loading…
Reference in New Issue