From 21bd1d080eb0833654d28fb34e2c6cf4eabe6197 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 28 Jan 2015 19:44:59 +0100 Subject: [PATCH] Refactorization: Rearranged some code in checkleakautovar.cpp --- lib/checkleakautovar.cpp | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index aa83bcca0..067f12ea7 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -358,8 +358,29 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, 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.. - 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); if (allocation.type == 0) 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 else if (tok->str() == "goto") { varInfo->clear(); @@ -412,21 +427,6 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, else if (Token::Match(tok, "continue|break ;")) { 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(); - } } }