Refactorization: Rearranged some code in checkleakautovar.cpp
This commit is contained in:
parent
0488f45a5f
commit
21bd1d080e
|
@ -358,8 +358,29 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return
|
||||||
|
else if (tok->str() == "return") {
|
||||||
|
ret(tok, *varInfo);
|
||||||
|
varInfo->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// throw
|
||||||
|
else if (tok->str() == "throw") {
|
||||||
|
bool tryFound = false;
|
||||||
|
const Scope* scope = tok->scope();
|
||||||
|
while (scope && scope->isExecutable()) {
|
||||||
|
if (scope->type == Scope::eTry)
|
||||||
|
tryFound = true;
|
||||||
|
scope = scope->nestedIn;
|
||||||
|
}
|
||||||
|
// If the execution leaves the function then treat it as return
|
||||||
|
if (!tryFound)
|
||||||
|
ret(tok, *varInfo);
|
||||||
|
varInfo->clear();
|
||||||
|
}
|
||||||
|
|
||||||
// Function call..
|
// Function call..
|
||||||
else if (Token::Match(tok, "%type% (") && tok->str() != "return" && tok->str() != "throw") {
|
else if (Token::Match(tok, "%type% (")) {
|
||||||
VarInfo::AllocInfo allocation(_settings->library.dealloc(tok), VarInfo::DEALLOC);
|
VarInfo::AllocInfo allocation(_settings->library.dealloc(tok), VarInfo::DEALLOC);
|
||||||
if (allocation.type == 0)
|
if (allocation.type == 0)
|
||||||
allocation.status = VarInfo::NOALLOC;
|
allocation.status = VarInfo::NOALLOC;
|
||||||
|
@ -397,12 +418,6 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return
|
|
||||||
else if (tok->str() == "return") {
|
|
||||||
ret(tok, *varInfo);
|
|
||||||
varInfo->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// goto => weird execution path
|
// goto => weird execution path
|
||||||
else if (tok->str() == "goto") {
|
else if (tok->str() == "goto") {
|
||||||
varInfo->clear();
|
varInfo->clear();
|
||||||
|
@ -412,21 +427,6 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
else if (Token::Match(tok, "continue|break ;")) {
|
else if (Token::Match(tok, "continue|break ;")) {
|
||||||
varInfo->clear();
|
varInfo->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// throw
|
|
||||||
else if (tok->str() == "throw") {
|
|
||||||
bool tryFound = false;
|
|
||||||
const Scope* scope = tok->scope();
|
|
||||||
while (scope && scope->isExecutable()) {
|
|
||||||
if (scope->type == Scope::eTry)
|
|
||||||
tryFound = true;
|
|
||||||
scope = scope->nestedIn;
|
|
||||||
}
|
|
||||||
// If the execution leaves the function then treat it as return
|
|
||||||
if (!tryFound)
|
|
||||||
ret(tok, *varInfo);
|
|
||||||
varInfo->clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue