memory leak: fixed false positive when using 'return strcpy'

This commit is contained in:
Daniel Marjamäki 2009-02-24 06:23:21 +00:00
parent 44a5cecd99
commit d15aea1b0c
2 changed files with 16 additions and 0 deletions

View File

@ -625,6 +625,11 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
}
}
}
else if (Token::Match(tok, ("return strcpy|strncpy ( " + varnameStr).c_str()))
{
addtoken("use");
tok = tok->tokAt(2);
}
}
// throw..

View File

@ -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());
}