Fixed false positive #6481

This commit is contained in:
PKEuS 2015-01-31 20:34:06 +01:00
parent 21cb0cfd60
commit 54b6b8e571
2 changed files with 7 additions and 1 deletions

View File

@ -2745,7 +2745,7 @@ void CheckMemoryLeakNoVar::check()
void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
{
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "%name% (") && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp())) {
if (Token::Match(tok, "%name% (") && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp()) && tok->next()->astOperand1() == tok) {
const AllocType allocType = getAllocationType(tok, 0);
if (allocType != No)
returnValueNotUsedError(tok, tok->str());

View File

@ -6503,6 +6503,12 @@ private:
" if(!malloc(5)) fail();\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function malloc is not stored.\n", errout.str());
check("FOO* factory() {\n"
" FOO* foo = new (std::nothrow) FOO;\n"
" return foo;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void smartPointerFunctionParam() {