From e7e23e87c2b4ee1855a643787e219fcb9532bdb0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 27 Jun 2022 19:35:22 +0200 Subject: [PATCH] Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) ) (#4237) * Fix #10857 FN: leakNoVarFunctionCall * Fix TODO * Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) ) --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 8d02e87e1..b9eb70d62 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -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()); } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 6d845c4e9..717212db8 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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() {