Refactoring of CheckOther::nullConstantDereference
This commit is contained in:
parent
33b4254d33
commit
28ad69e4b3
|
@ -2201,13 +2201,34 @@ void CheckOther::nullPointer()
|
||||||
/** Derefencing null constant (simplified token list) */
|
/** Derefencing null constant (simplified token list) */
|
||||||
void CheckOther::nullConstantDereference()
|
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())
|
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"))
|
if (tok->str() == "(" && Token::simpleMatch(tok->previous(), "sizeof"))
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
|
||||||
else if (Token::simpleMatch(tok, "exit ( )"))
|
else if (Token::simpleMatch(tok, "exit ( )"))
|
||||||
{
|
{
|
||||||
|
// Goto end of scope
|
||||||
while (tok && tok->str() != "}")
|
while (tok && tok->str() != "}")
|
||||||
{
|
{
|
||||||
if (tok->str() == "{")
|
if (tok->str() == "{")
|
||||||
|
@ -2226,6 +2247,7 @@ void CheckOther::nullConstantDereference()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief parse a function call and extract information about variable usage
|
* \brief parse a function call and extract information about variable usage
|
||||||
|
|
Loading…
Reference in New Issue