Part of fix for ticket #284 (style check: redundant condition improvement)
Fixed case "if (p != NULL) delete p;" and also added test case for it. http://apps.sourceforge.net/trac/cppcheck/ticket/284
This commit is contained in:
parent
1e2545439e
commit
bc62472a18
|
@ -82,7 +82,7 @@ void CheckOther::WarningRedundantCode()
|
|||
varname1 = tok->strAt(2);
|
||||
tok2 = tok->tokAt(4);
|
||||
}
|
||||
else if (Token::Match(tok, "if ( %var% != NULL )"))
|
||||
else if (Token::Match(tok, "if ( %var% != 0 )"))
|
||||
{
|
||||
varname1 = tok->strAt(2);
|
||||
tok2 = tok->tokAt(6);
|
||||
|
|
|
@ -145,6 +145,13 @@ private:
|
|||
" delete p;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
" if (p != NULL)\n"
|
||||
" delete p;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str());
|
||||
}
|
||||
|
||||
void unreachable1()
|
||||
|
|
Loading…
Reference in New Issue