Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) ) (#4237)

* Fix #10857 FN: leakNoVarFunctionCall

* Fix TODO

* Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) )
This commit is contained in:
chrchr-github 2022-06-27 19:35:22 +02:00 committed by GitHub
parent 88bf11abba
commit e7e23e87c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -1070,7 +1070,7 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
if (closingBrace->str() == "}" && Token::Match(closingBrace->link()->tokAt(-1), "%name%") && (!isNew && precedes(tok, closingBrace->link())))
continue;
returnValueNotUsedError(tok, tok->str());
} else if (Token::Match(parent, "%comp%|!|,")) {
} else if (Token::Match(parent, "%comp%|!|,|%oror%|&&")) {
if (!(parent->astParent() && parent->str() == ","))
returnValueNotUsedError(tok, tok->str());
}

View File

@ -2601,6 +2601,12 @@ private:
" C{ new QWidget, 1 };\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(bool b) { if (b && malloc(42)) {} }\n" // // #10858
"void g(bool b) { if (b || malloc(42)) {} }\n");
ASSERT_EQUALS("[test.cpp:1]: (error) Return value of allocation function 'malloc' is not stored.\n"
"[test.cpp:2]: (error) Return value of allocation function 'malloc' is not stored.\n",
errout.str());
}
void smartPointerFunctionParam() {