memory leak: Added command line flag '--vcl' that is used to suppress error messages for VCL code

This commit is contained in:
Daniel Marjamäki 2009-02-20 06:28:18 +00:00
parent 4fc774deda
commit 385be6d0d9
6 changed files with 58 additions and 3 deletions

View File

@ -426,7 +426,19 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
if (isclass(tok->tokAt(3)))
{
if (_settings._showAll)
{
if (_settings._vcl && Token::Match(tok->tokAt(4), "( %var%") && (tok->strAt(3)[0] == 'T'))
{
// Guess this is a VCL class with automatic deallocation
alloc = No;
}
else
{
// The checking will proceed.. but any error messages that are shown are shown thanks to "--all"
all = true;
}
}
else
alloc = No;
}

View File

@ -104,6 +104,10 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
else if (strcmp(argv[i], "--unused-functions") == 0)
_settings._unusedFunctions = true;
// Write results in results.xml
else if (strcmp(argv[i], "--vcl") == 0)
_settings._vcl = true;
// Print help
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
@ -169,7 +173,7 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
"\n"
"Syntax:\n"
" cppcheck [--all] [--force] [--help] [-Idir] [--quiet] [--style]\n"
" [--unused-functions] [--verbose] [--xml]\n"
" [--unused-functions] [--verbose] [--vcl] [--xml]\n"
" [file or path1] [file or path]\n"
"\n"
"If path is given instead of filename, *.cpp, *.cxx, *.cc, *.c++ and *.c files\n"
@ -186,6 +190,7 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
" -q, --quiet Only print error messages\n"
" -s, --style Check coding style\n"
" --unused-functions Check if there are unused functions\n"
" --vcl Suppress messages about memory leaks when using VCL classes\n"
" -v, --verbose More detailed error reports\n"
" --xml Write results in xml to error stream.\n"
"\n"

View File

@ -56,7 +56,7 @@ public:
std::string toXML() const;
std::string toText() const;
std::string serialize() const;
bool deserialize( const std::string &data );
bool deserialize(const std::string &data);
private:
std::list<FileLocation> _callStack;
std::string _severity;

View File

@ -30,6 +30,7 @@ Settings::Settings()
_xml = false;
_unusedFunctions = false;
_security = false;
_vcl = false;
}
Settings::~Settings()

View File

@ -48,6 +48,9 @@ public:
/** Security checks */
bool _security;
/** Disable warnings for VCL classes */
bool _vcl;
};
#endif // SETTINGS_H

View File

@ -192,6 +192,9 @@ private:
TEST_CASE(unknownFunction1);
TEST_CASE(unknownFunction2);
TEST_CASE(unknownFunction3);
// VCL..
TEST_CASE(vcl1);
}
@ -1886,6 +1889,37 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
}
void vcl1()
{
const char code[] = "void Form1::foo()\n"
"{\n"
" TEdit *Edit1 = new TEdit(this);\n"
"}\n";
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
tokenizer.simplifyTokenList();
// Clear the error buffer..
errout.str("");
// Check for memory leaks..
Settings settings;
settings._debug = true;
settings._showAll = true;
settings._vcl = true;
CheckMemoryLeakClass checkMemoryLeak(&tokenizer, settings, this);
checkMemoryLeak.CheckMemoryLeak();
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestMemleak)