From d15aea1b0caa0b8e976ef0f450404d0465eab257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Feb 2009 06:23:21 +0000 Subject: [PATCH] memory leak: fixed false positive when using 'return strcpy' --- src/checkmemoryleak.cpp | 5 +++++ test/testmemleak.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 7b1d27721..4aae5bbdb 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -625,6 +625,11 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list } } } + else if (Token::Match(tok, ("return strcpy|strncpy ( " + varnameStr).c_str())) + { + addtoken("use"); + tok = tok->tokAt(2); + } } // throw.. diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 033ee3be4..f2f80a7f0 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -120,6 +120,7 @@ private: TEST_CASE(ret3); TEST_CASE(ret4); TEST_CASE(ret5); // Bug 2458436 - return use + TEST_CASE(ret6); TEST_CASE(mismatch1); TEST_CASE(mismatch2); @@ -986,6 +987,16 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void ret6() + { + check("void foo()\n" + "{\n" + " char *c = new char[50];\n" + " return strcpy(c, \"foo\");\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } +