Code cleanup: Removed autodealloc handling

This commit is contained in:
Daniel Marjamki 2010-05-16 07:15:31 +02:00
parent 8e3c39ae5b
commit d7b117402c
7 changed files with 20 additions and 150 deletions

View File

@ -105,10 +105,13 @@ void CheckExceptionSafety::unsafeNew()
unsafeNewError(tok->previous(), varname);
break;
}
/*
// TODO: check if class is autodeallocated+might throw exception in constructor
if (!_settings->isAutoDealloc(tok->strAt(2)))
{
varname = tok->strAt(-1);
}
*/
}
tok = tok->link();
tok = tok ? tok->next() : 0;
@ -152,8 +155,11 @@ void CheckExceptionSafety::unsafeNew()
unsafeNewError(tok, varname);
break;
}
/*
TODO: check is class is autodeallocated + might throw exceptions in the constructor
if (!_settings->isAutoDealloc(tok->strAt(3)))
varname = tok->str();
*/
}
}
}
@ -170,7 +176,7 @@ void CheckExceptionSafety::unsafeNew()
}
if (Token::Match(tok, "[;{}] %type% * %var% ;") &&
!_settings->isAutoDealloc(tok->strAt(1)))
tok->tokAt(1)->isStandardType())
{
tok = tok->tokAt(3);
if (tok->varId())

View File

@ -815,29 +815,14 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
}
}
// If "--all" hasn't been given, don't check classes..
// don't check classes..
if (alloc == CheckMemoryLeak::New)
{
if (Token::Match(tok->tokAt(2), "new %type% [(;]"))
{
if (isclass(_tokenizer, tok->tokAt(3)))
{
if (_settings->inconclusive)
{
if (_settings->isAutoDealloc(tok->strAt(3)))
{
// This class has 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;
alloc = No;
}
}
}
@ -2366,11 +2351,7 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<std::stri
if (privateScope && tok->isStandardType())
checkPublicFunctions(tok1, tok->tokAt(2)->varId());
// No false positives for auto deallocated classes..
if (_settings->isAutoDealloc(tok->str().c_str()))
continue;
if (_settings->inconclusive || !isclass(_tokenizer, tok))
if (!isclass(_tokenizer, tok))
variable(classname.back(), tok->tokAt(2));
}
}

View File

@ -464,25 +464,10 @@ bool CppCheck::parseFromArgs(int argc, const char* const argv[])
}
}
// auto deallocated classes..
// deprecated: auto deallocated classes..
else if (strcmp(argv[i], "--auto-dealloc") == 0)
{
++i;
if (i >= argc || !strstr(argv[i], ".lst"))
{
reportOut("cppcheck: No .lst file specified for the --auto-dealloc option");
return false;
}
std::ifstream f(argv[i]);
if (!f.is_open())
{
reportOut("cppcheck: couldn't open the file \"" + std::string(argv[i+1]) + "\"");
return false;
}
_settings.autoDealloc(f);
}
// print all possible error messages..

View File

@ -40,21 +40,6 @@ Settings::Settings()
inconclusive = false;
}
void Settings::autoDealloc(std::istream &istr)
{
std::string line;
while (getline(istr, line))
{
// Check if line has a valid classname..
if (line.empty())
continue;
// Add classname to list
_autoDealloc.insert(line);
}
}
bool Settings::Suppressions::parseFile(std::istream &istr)
{
std::string line;
@ -168,16 +153,6 @@ bool Settings::isEnabled(const std::string &str) const
return bool(_enabled.find(str) != _enabled.end());
}
void Settings::addAutoAllocClass(const std::string &name)
{
_autoDealloc.insert(name);
}
bool Settings::isAutoDealloc(const std::string &classname) const
{
return (_autoDealloc.find(classname) != _autoDealloc.end());
}
void Settings::append(const std::string &filename)
{

View File

@ -37,9 +37,6 @@
class Settings
{
private:
/** @brief classes that are automaticly deallocated */
std::set<std::string> _autoDealloc;
/** @brief Code to append in the checks */
std::string _append;
@ -107,15 +104,6 @@ public:
for finding include files inside source files. (-I) */
std::list<std::string> _includePaths;
/** @brief Fill list of automaticly deallocated classes (--auto-dealloc) */
void autoDealloc(std::istream &istr);
/** @brief Add class to list of automatically deallocated classes */
void addAutoAllocClass(const std::string &name);
/** @brief is a class automaticly deallocated? */
bool isAutoDealloc(const std::string &classname) const;
/** @brief assign append code (--append) */
void append(const std::string &filename);

View File

@ -41,7 +41,7 @@ private:
TEST_CASE(deallocThrow);
}
void check(const std::string &code, const std::string &autodealloc = "")
void check(const std::string &code)
{
// Tokenize..
Tokenizer tokenizer;
@ -55,8 +55,6 @@ private:
// Check char variable usage..
Settings settings;
settings.addEnabled("all");
std::istringstream istr2(autodealloc.c_str());
settings.autoDealloc(istr2);
CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this);
checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this);
}
@ -73,24 +71,24 @@ private:
void newnew()
{
check("C::C() : a(new A), b(new B) { }");
ASSERT_EQUALS("[test.cpp:1]: (style) Upon exception there is memory leak: a\n", errout.str());
check("C::C() : a(new A), b(new B) { }", "A\nB\n");
ASSERT_EQUALS("", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:1]: (style) Upon exception there is memory leak: a\n", errout.str());
check("C::C()\n"
"{\n"
" a = new A;\n"
" b = new B;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Upon exception there is memory leak: a\n", errout.str());
ASSERT_EQUALS("", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Upon exception there is memory leak: a\n", errout.str());
check("void a()\n"
"{\n"
" A *a1 = new A;\n"
" A *a2 = new A;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Upon exception there is memory leak: a1\n", errout.str());
ASSERT_EQUALS("", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Upon exception there is memory leak: a1\n", errout.str());
check("void a()\n"
"{\n"
@ -112,7 +110,7 @@ private:
"{\n"
" A *a = new A;\n"
" B *b = new B;\n"
"}\n", "A\n");
"}\n");
ASSERT_EQUALS("", errout.str());
// passing pointer to unknown function.. the pointer may be added to some list etc..
@ -121,7 +119,7 @@ private:
" A *a1 = new A;\n"
" add(a1);\n"
" A *a2 = new A;\n"
"}\n", "");
"}\n");
ASSERT_EQUALS("", errout.str());
}

View File

@ -340,10 +340,6 @@ private:
TEST_CASE(unknownFunction4);
TEST_CASE(unknownFunction5);
// VCL..
TEST_CASE(vcl1);
TEST_CASE(vcl2);
// detect leak in class member function..
TEST_CASE(class1);
@ -2084,12 +2080,6 @@ private:
" Fred *f = new Fred;\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());
check("void foo()\n"
"{\n"
" Fred *f = new Fred;\n"
"}\n", true);
ASSERT_EQUALS("[test.cpp:4]: (possible error) Memory leak: f\n", errout.str());
}
@ -2184,7 +2174,7 @@ private:
}
void checkvcl(const char code[], const char _autoDealloc[])
void checkvcl(const char code[])
{
// Tokenize..
Tokenizer tokenizer;
@ -2202,45 +2192,11 @@ private:
Settings settings;
settings.inconclusive = true;
{
std::istringstream istr(_autoDealloc);
settings.autoDealloc(istr);
}
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.check();
}
void vcl1()
{
checkvcl("void Form1::foo()\n"
"{\n"
" TEdit *Edit1 = new TEdit(this);\n"
"}\n", "TEdit\n");
ASSERT_EQUALS("", errout.str());
}
void vcl2()
{
checkvcl("class Fred\n"
"{\n"
"private:\n"
" TButton *button;\n"
"public:\n"
" Fred();\n"
"};\n"
"\n"
"Fred::Fred()\n"
"{\n"
" button = new TButton(this);\n"
"}\n", "TButton\n");
ASSERT_EQUALS("", errout.str());
}
void class1()
{
check("class Fred\n"
@ -2811,8 +2767,6 @@ private:
TEST_CASE(staticvar);
TEST_CASE(use);
TEST_CASE(free_member_in_sub_func);
TEST_CASE(mismatch1);
@ -3126,23 +3080,6 @@ private:
}
void use()
{
check("class A\n"
"{\n"
"public:\n"
" Fred * fred;\n"
" A();\n"
"};\n"
"A::A()\n"
"{\n"
" fred = new Fred;\n"
" list->push_back(fred);\n"
"}", true);
TODO_ASSERT_EQUALS("", errout.str());
}
void free_member_in_sub_func()
{
// Member function