From 435888f82eef121a5c47d6827febfd06c4355ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 13 Jul 2018 16:57:17 +0200 Subject: [PATCH] Refactoring; use range for loop --- lib/checktype.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/checktype.cpp b/lib/checktype.cpp index fb6652ff7..21652f5c3 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -293,9 +293,7 @@ void CheckType::checkLongCast() // Return.. const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); - const std::size_t functions = symbolDatabase->functionScopes.size(); - for (std::size_t i = 0; i < functions; ++i) { - const Scope * scope = symbolDatabase->functionScopes[i]; + for (const Scope * scope : symbolDatabase->functionScopes) { // function must return long data const Token * def = scope->classDef; @@ -385,15 +383,15 @@ void CheckType::checkFloatToIntegerOverflow() if (!vtfloat || !vtfloat->isFloat()) continue; - for (std::list::const_iterator it = floatValues->begin(); it != floatValues->end(); ++it) { - if (it->valueType != ValueFlow::Value::FLOAT) + for (const ValueFlow::Value &f : *floatValues) { + if (f.valueType != ValueFlow::Value::FLOAT) continue; - if (!mSettings->isEnabled(&(*it), false)) + if (!mSettings->isEnabled(&f, false)) continue; - if (it->floatValue > ~0ULL) - floatToIntegerOverflowError(tok, *it); - else if ((-it->floatValue) > (1ULL<<62)) - floatToIntegerOverflowError(tok, *it); + if (f.floatValue > ~0ULL) + floatToIntegerOverflowError(tok, f); + else if ((-f.floatValue) > (1ULL<<62)) + floatToIntegerOverflowError(tok, f); else if (mSettings->platformType != Settings::Unspecified) { int bits = 0; if (vtint->type == ValueType::Type::CHAR) @@ -408,8 +406,8 @@ void CheckType::checkFloatToIntegerOverflow() bits = mSettings->long_long_bit; else continue; - if (bits < MathLib::bigint_bits && it->floatValue >= (((MathLib::biguint)1) << bits)) - floatToIntegerOverflowError(tok, *it); + if (bits < MathLib::bigint_bits && f.floatValue >= (((MathLib::biguint)1) << bits)) + floatToIntegerOverflowError(tok, f); } } }