memory leak: Added command line flag '--vcl' that is used to suppress error messages for VCL code
This commit is contained in:
parent
4fc774deda
commit
385be6d0d9
|
@ -426,7 +426,19 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
if (isclass(tok->tokAt(3)))
|
if (isclass(tok->tokAt(3)))
|
||||||
{
|
{
|
||||||
if (_settings._showAll)
|
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;
|
all = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
alloc = No;
|
alloc = No;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,10 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (strcmp(argv[i], "--unused-functions") == 0)
|
else if (strcmp(argv[i], "--unused-functions") == 0)
|
||||||
_settings._unusedFunctions = true;
|
_settings._unusedFunctions = true;
|
||||||
|
|
||||||
|
// Write results in results.xml
|
||||||
|
else if (strcmp(argv[i], "--vcl") == 0)
|
||||||
|
_settings._vcl = true;
|
||||||
|
|
||||||
// Print help
|
// Print help
|
||||||
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
|
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"
|
"\n"
|
||||||
"Syntax:\n"
|
"Syntax:\n"
|
||||||
" cppcheck [--all] [--force] [--help] [-Idir] [--quiet] [--style]\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"
|
" [file or path1] [file or path]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"If path is given instead of filename, *.cpp, *.cxx, *.cc, *.c++ and *.c files\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"
|
" -q, --quiet Only print error messages\n"
|
||||||
" -s, --style Check coding style\n"
|
" -s, --style Check coding style\n"
|
||||||
" --unused-functions Check if there are unused functions\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"
|
" -v, --verbose More detailed error reports\n"
|
||||||
" --xml Write results in xml to error stream.\n"
|
" --xml Write results in xml to error stream.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
std::string toXML() const;
|
std::string toXML() const;
|
||||||
std::string toText() const;
|
std::string toText() const;
|
||||||
std::string serialize() const;
|
std::string serialize() const;
|
||||||
bool deserialize( const std::string &data );
|
bool deserialize(const std::string &data);
|
||||||
private:
|
private:
|
||||||
std::list<FileLocation> _callStack;
|
std::list<FileLocation> _callStack;
|
||||||
std::string _severity;
|
std::string _severity;
|
||||||
|
|
|
@ -30,6 +30,7 @@ Settings::Settings()
|
||||||
_xml = false;
|
_xml = false;
|
||||||
_unusedFunctions = false;
|
_unusedFunctions = false;
|
||||||
_security = false;
|
_security = false;
|
||||||
|
_vcl = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::~Settings()
|
Settings::~Settings()
|
||||||
|
|
|
@ -48,6 +48,9 @@ public:
|
||||||
|
|
||||||
/** Security checks */
|
/** Security checks */
|
||||||
bool _security;
|
bool _security;
|
||||||
|
|
||||||
|
/** Disable warnings for VCL classes */
|
||||||
|
bool _vcl;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
|
|
@ -192,6 +192,9 @@ private:
|
||||||
TEST_CASE(unknownFunction1);
|
TEST_CASE(unknownFunction1);
|
||||||
TEST_CASE(unknownFunction2);
|
TEST_CASE(unknownFunction2);
|
||||||
TEST_CASE(unknownFunction3);
|
TEST_CASE(unknownFunction3);
|
||||||
|
|
||||||
|
// VCL..
|
||||||
|
TEST_CASE(vcl1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1886,6 +1889,37 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
|
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)
|
REGISTER_TEST(TestMemleak)
|
||||||
|
|
Loading…
Reference in New Issue