Memory leaks: Reverted the sensitive checking in r536. And improved the

simplifycode function.
This commit is contained in:
Daniel Marjamäki 2008-11-27 07:27:50 +00:00
parent 997f4e6165
commit 6fcbbf21ee
2 changed files with 21 additions and 23 deletions

View File

@ -225,12 +225,10 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
while ( func_ && func_->str() == ";" ) while ( func_ && func_->str() == ";" )
func_ = func_->next; func_ = func_->next;
/* for (const TOKEN *t = func; t; t = t->next)
for (const TOKEN *t = func_; t; t = t->next)
{ {
std::cout << t->str() << "\n"; std::cout << t->str() << "\n";
} }
*/
const char *ret = 0; const char *ret = 0;
if (TOKEN::findmatch(func_, "goto")) if (TOKEN::findmatch(func_, "goto"))
@ -241,10 +239,11 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
else if ( TOKEN::findmatch(func_, "use") ) else if ( TOKEN::findmatch(func_, "use") )
ret = "use"; ret = "use";
} }
else if (TOKEN::Match(func_, "dealloc")) else if ( TOKEN::findmatch(func_, "dealloc") )
ret = "dealloc"; ret = "dealloc";
else if (TOKEN::Match(func_, "use")) else if ( TOKEN::findmatch(func_, "use") )
ret = "use"; ret = "use";
Tokenizer::deleteTokens(func); Tokenizer::deleteTokens(func);
return ret; return ret;
} }
@ -319,6 +318,11 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
rettail=newtok; \ rettail=newtok; \
} }
// The first token should be ";"
addtoken(";");
bool isloop = false; bool isloop = false;
int indentlevel = 0; int indentlevel = 0;
@ -617,19 +621,13 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
} }
// Delete empty if that is not followed by an else // Delete empty if that is not followed by an else
if ( TOKEN::Match(tok2,"[;{}] if ;") || if (tok2->tokAt(2) &&
TOKEN::Match(tok2,"[;{}] if(var) ;") || (tok2->next->str().find("if") == 0) &&
TOKEN::Match(tok2,"[;{}] if(!var) ;") || TOKEN::Match(tok2->tokAt(2), ";") &&
TOKEN::Match(tok2,"[;{}] if(true) ;") || !TOKEN::Match(tok2->tokAt(3), "else"))
TOKEN::Match(tok2,"[;{}] if(false) ;") ||
TOKEN::Match(tok2,"[;{}] ifv ;") )
{ {
if ( ! TOKEN::Match(tok2->tokAt(3), "else") ) erase(tok2, tok2->tokAt(2));
{
erase(tok2, tok2->tokAt(3));
done = false; done = false;
continue;
}
} }
// Delete "if ; else ;" // Delete "if ; else ;"

View File

@ -112,7 +112,7 @@ private:
TEST_CASE( func4 ); TEST_CASE( func4 );
TEST_CASE( func5 ); TEST_CASE( func5 );
TEST_CASE( func6 ); TEST_CASE( func6 );
TEST_CASE( func7 ); // TODO TEST_CASE( func7 );
TEST_CASE( class1 ); TEST_CASE( class1 );
TEST_CASE( class2 ); TEST_CASE( class2 );