From 2f0fc9444ff50210f59b7c07e34074158671df00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 23 Aug 2011 23:18:47 +0200 Subject: [PATCH] Fixed #3041 (false positive reported for error with id='deallocuse') --- lib/checkmemoryleak.cpp | 9 ++++++++- test/testmemleak.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index d8533aa4a..f1736b9e8 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -697,7 +697,14 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::liststr() == "(" || tok2->str() == ")") break; if (tok2->varId() == varid) - return (tok->strAt(-1)==".") ? "use" : "use_"; + { + if (tok->strAt(-1) == ".") + return "use"; + else if (tok2->strAt(1) == "=") + return "assign"; + else + return"use_"; + } } return 0; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 71080f83f..408fa60c9 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -276,6 +276,7 @@ private: // * It is ok to take the address to deallocated memory // * It is not ok to dereference a pointer to deallocated memory TEST_CASE(dealloc_use); + TEST_CASE(dealloc_use_2); // free a free'd pointer TEST_CASE(freefree1); @@ -2962,6 +2963,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void dealloc_use_2() + { + // #3041 - assigning pointer when it's used + check("void f(char *s) {\n" + " free(s);\n" + " strcpy(a, s=b());\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void freefree1() {