Refactoring: Use the Token::link instead of loop

This commit is contained in:
Daniel Marjamäki 2009-08-17 22:23:37 +02:00
parent 40fc605e2b
commit 2cdb0abb82
3 changed files with 18 additions and 39 deletions

View File

@ -267,9 +267,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con
if (value <= size)
condition_out_of_bounds = false;;
// Goto the end of the for loop..
while (tok2 && tok2->str() != ")")
tok2 = tok2->next();
// Goto the end paranthesis of the for-statement: "for (x; y; z)" ..
tok2 = tok->next()->link();
if (!tok2 || !tok2->tokAt(5))
break;

View File

@ -62,8 +62,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
// * var = strndup("hello", 3);
if (tok2 && tok2->str() == "(")
{
while (tok2 && tok2->str() != ")")
tok2 = tok2->next();
tok2 = tok2->link();
tok2 = tok2 ? tok2->next() : NULL;
}
if (! tok2)
@ -143,8 +142,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok
// * var = (char *)realloc(..;
if (tok2 && tok2->str() == "(")
{
while (tok2 && tok2->str() != ")")
tok2 = tok2->next();
tok2 = tok2->link();
tok2 = tok2 ? tok2->next() : NULL;
}
if (! tok2)
@ -735,8 +733,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
addtoken("if(var)");
// Make sure the "use" will not be added
while (tok->str() != ")")
tok = tok->next();
tok = tok->next()->link();
}
else if (Token::simpleMatch(tok, std::string("if ( " + varnameStr + " == -1 )").c_str()) ||
Token::simpleMatch(tok, std::string("if ( " + varnameStr + " < 0 )").c_str()))
@ -2068,24 +2065,14 @@ void CheckMemoryLeakStructMember::check()
else if (Token::Match(tok3, "if ( ! %var% . %varid% )", structmemberid))
{
// Goto the ")"
while (tok3->str() != ")")
tok3 = tok3->next();
tok3 = tok3->next()->link();
// Skip block..
unsigned int indentlevel = 0;
while (tok3)
{
if (tok3->str() == "{")
++indentlevel;
else if (tok3->str() == "}")
{
if (indentlevel <= 1)
// make sure we have ") {".. it should be
if (!Token::simpleMatch(tok3, ") {"))
break;
--indentlevel;
}
tok3 = tok3->next();
}
// Goto the "}"
tok3 = tok3->next()->link();
}
// Returning from function..

View File

@ -977,24 +977,17 @@ void CheckOther::nullPointer()
// Locate the end of the while loop..
const Token *tok2 = tok->tokAt(4);
int indentlevel = 0;
while (tok2)
{
if (tok2->str() == "{")
++indentlevel;
else if (tok2->str() == "}")
tok2 = tok2->link();
else
{
if (indentlevel <= 1)
break;
--indentlevel;
}
else if (indentlevel == 0 && tok2->str() == ";")
break;
while (tok2 && tok2->str() != ";")
tok2 = tok2->next();
}
// Goto next token
tok2 = tok2 ? tok2->next() : 0;
if (tok2)
tok2 = tok2->next();
// Check if the variable is dereferenced..
while (tok2)