Refactor lib/checkuninitvar.cpp

This commit is contained in:
jrp2014 2018-04-06 08:04:06 +02:00 committed by Daniel Marjamäki
parent 15b5b7ebf4
commit d2160f00b2
1 changed files with 3 additions and 6 deletions

View File

@ -57,7 +57,6 @@ static const struct CWE CWE825(825U);
void CheckUninitVar::check() void CheckUninitVar::check()
{ {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
std::list<Scope>::const_iterator scope;
std::set<std::string> arrayTypeDefs; std::set<std::string> arrayTypeDefs;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
@ -66,7 +65,7 @@ void CheckUninitVar::check()
} }
// check every executable scope // check every executable scope
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
if (scope->isExecutable()) { if (scope->isExecutable()) {
checkScope(&*scope, arrayTypeDefs); checkScope(&*scope, arrayTypeDefs);
} }
@ -1226,10 +1225,9 @@ void CheckUninitVar::uninitStructMemberError(const Token *tok, const std::string
void CheckUninitVar::valueFlowUninit() void CheckUninitVar::valueFlowUninit()
{ {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
std::list<Scope>::const_iterator scope;
// check every executable scope // check every executable scope
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
if (!scope->isExecutable()) if (!scope->isExecutable())
continue; continue;
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
@ -1252,10 +1250,9 @@ void CheckUninitVar::valueFlowUninit()
void CheckUninitVar::deadPointer() void CheckUninitVar::deadPointer()
{ {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
std::list<Scope>::const_iterator scope;
// check every executable scope // check every executable scope
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
if (!scope->isExecutable()) if (!scope->isExecutable())
continue; continue;
// Dead pointers.. // Dead pointers..