From 04ceae7ea7b026af9bdabec0f1187e1c8212820d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=E4ki?= Date: Sat, 26 Jan 2013 07:28:11 +0100 Subject: [PATCH] Uninitialized variables: minor refactorings --- lib/checkuninitvar.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 9dd7b5520..1596d9e69 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1043,13 +1043,12 @@ void CheckUninitVar::executionPaths() void CheckUninitVar::check() { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); - std::list::const_iterator func_scope; + std::list::const_iterator scope; - // scan every function - for (func_scope = symbolDatabase->scopeList.begin(); func_scope != symbolDatabase->scopeList.end(); ++func_scope) { - // only check functions - if (func_scope->type == Scope::eFunction) { - checkScope(&*func_scope); + // check every executable scope + for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { + if (scope->isExecutable()) { + checkScope(&*scope); } } } @@ -1067,7 +1066,7 @@ void CheckUninitVar::checkScope(const Scope* scope) if (tok->str() == "(") { forHead = true; break; - } else if (tok->str() == "{" || tok->str() == ";" || tok->str() == "}") + } else if (Token::Match(tok, "[{};]")) break; } if (forHead) @@ -1095,11 +1094,6 @@ void CheckUninitVar::checkScope(const Scope* scope) } } } - - for (std::list::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) { - if (!(*i)->isClassOrStruct()) - checkScope(*i); - } } static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map &variableValue, bool *alwaysTrue, bool *alwaysFalse)