Fixed false positive #6481
This commit is contained in:
parent
21cb0cfd60
commit
54b6b8e571
|
@ -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());
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue