Refactoring of CheckOther::nullConstantDereference

This commit is contained in:
Daniel Marjamäki 2010-06-02 17:53:45 +02:00
parent 33b4254d33
commit 28ad69e4b3
1 changed files with 35 additions and 13 deletions

View File

@ -2201,13 +2201,34 @@ void CheckOther::nullPointer()
/** Derefencing null constant (simplified token list) */
void CheckOther::nullConstantDereference()
{
// this is kept at 0 for all scopes that are not executing
unsigned int indentlevel = 0;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
// start of executable scope..
if (indentlevel == 0 && Token::Match(tok, ") const| {"))
indentlevel = 1;
else if (indentlevel >= 1)
{
if (tok->str() == "{")
++indentlevel;
else if (tok->str() == "}")
{
if (indentlevel <= 2)
indentlevel = 0;
else
--indentlevel;
}
if (tok->str() == "(" && Token::simpleMatch(tok->previous(), "sizeof"))
tok = tok->link();
else if (Token::simpleMatch(tok, "exit ( )"))
{
// Goto end of scope
while (tok && tok->str() != "}")
{
if (tok->str() == "{")
@ -2225,6 +2246,7 @@ void CheckOther::nullConstantDereference()
}
}
}
}
}
/**