From 832275bc37200e6266a7dd2cb8aa448885a355b7 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Tue, 3 Mar 2009 20:39:17 +0000 Subject: [PATCH] Fix #132 (False positive returning memcpy()) --- src/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 7bb66975d..6c30e08ea 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -625,7 +625,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list } } } - else if (Token::Match(tok, ("return strcpy|strncpy ( " + varnameStr).c_str())) + else if (Token::Match(tok, ("return strcpy|strncpy|memcpy ( " + varnameStr).c_str())) { addtoken("use"); tok = tok->tokAt(2); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 062233531..f0df73ca8 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -122,6 +122,7 @@ private: TEST_CASE(ret4); TEST_CASE(ret5); // Bug 2458436 - return use TEST_CASE(ret6); + TEST_CASE(ret7); TEST_CASE(mismatch1); TEST_CASE(mismatch2); @@ -1016,7 +1017,15 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } - + void ret7() + { + check("void foo()\n" + "{\n" + " char *c = new char[50];\n" + " return memcpy(c, \"foo\",4);\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } void mismatch1()