diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 2f4ed2fea..93a0951ed 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -718,8 +718,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector callstack; - callstack.push_back(tok); + std::list callstack(1, tok); const Token* tok2 = tok->tokAt(2); if (Token::Match(tok2, (varnames + " ,").c_str())) checkFunctionParameter(*tok, 1, arrayInfo, callstack); @@ -1194,9 +1193,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() if (index < (isAddressOf(tok) ? elements + 1U : elements)) continue; - std::list callstack; - callstack.push_back(it->tokvalue); - callstack.push_back(tok); + std::list callstack = { it->tokvalue, tok }; std::vector indexes2(indexes.size()); for (unsigned int i = 0; i < indexes.size(); ++i) @@ -1370,9 +1367,7 @@ void CheckBufferOverrun::checkStructVariable() if (scope->nestedIn->isClassOrStruct()) continue; - std::vector varname; - varname.push_back(NULL); - varname.push_back(&arrayInfo.varname()); + std::vector varname = { nullptr, &arrayInfo.varname() }; // search the function and it's parameters for (const Token *tok3 = func_scope->classDef; tok3 && tok3 != func_scope->classEnd; tok3 = tok3->next()) { @@ -2106,8 +2101,7 @@ bool CheckBufferOverrun::analyseWholeProgram(const std::list & fileLoc.setfile(it->second.fileName); fileLoc.line = it->second.linenr; - std::list locationList; - locationList.push_back(fileLoc); + std::list locationList(1, fileLoc); std::ostringstream ostr; ostr << "Array " << it->first << '[' << sz->second << "] accessed at index " << it->second.index << " which is out of bounds"; diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index f3e8c5165..15bc46264 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1159,9 +1159,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco void CheckClass::mallocOnClassWarning(const Token* tok, const std::string &memfunc, const Token* classTok) { - std::list toks; - toks.push_back(tok); - toks.push_back(classTok); + std::list toks = { tok, classTok }; reportError(toks, Severity::warning, "mallocOnClassWarning", "$symbol:" + memfunc +"\n" "Memory for class instance allocated with $symbol(), but class provides constructors.\n" @@ -1171,9 +1169,7 @@ void CheckClass::mallocOnClassWarning(const Token* tok, const std::string &memfu void CheckClass::mallocOnClassError(const Token* tok, const std::string &memfunc, const Token* classTok, const std::string &classname) { - std::list toks; - toks.push_back(tok); - toks.push_back(classTok); + std::list toks = { tok, classTok }; reportError(toks, Severity::error, "mallocOnClassError", "$symbol:" + memfunc +"\n" "$symbol:" + classname +"\n" @@ -2146,9 +2142,7 @@ void CheckClass::initializerListOrder() void CheckClass::initializerListError(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &varname) { - std::list toks; - toks.push_back(tok1); - toks.push_back(tok2); + std::list toks = { tok1, tok2 }; reportError(toks, Severity::style, "initializerList", "$symbol:" + classname + "::" + varname +"\n" "Member variable '$symbol' is in the wrong place in the initializer list.\n" @@ -2210,8 +2204,7 @@ void CheckClass::checkVirtualFunctionCallInConstructor() const std::list & virtualFunctionCalls = getVirtualFunctionCalls(*scope->function, virtualFunctionCallsMap); for (std::list::const_iterator it = virtualFunctionCalls.begin(); it != virtualFunctionCalls.end(); ++it) { const Token * callToken = *it; - std::list callstack; - callstack.push_back(callToken); + std::list callstack(1, callToken); getFirstVirtualFunctionCallStack(virtualFunctionCallsMap, callToken, callstack); if (callstack.empty()) continue; @@ -2398,9 +2391,7 @@ void CheckClass::duplInheritedMembersError(const Token *tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct) { - std::list toks; - toks.push_back(tok1); - toks.push_back(tok2); + std::list toks = { tok1, tok2 }; const std::string symbols = "$symbol:" + derivedname + "\n$symbol:" + variablename + "\n$symbol:" + basename; diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 063eaff5b..289286e6e 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -206,10 +206,7 @@ bool CheckCondition::assignIfParseScope(const Token * const assignTok, void CheckCondition::assignIfError(const Token *tok1, const Token *tok2, const std::string &condition, bool result) { - std::list locations; - locations.push_back(tok1); - locations.push_back(tok2); - + std::list locations = { tok1, tok2 }; reportError(locations, Severity::style, "assignIfError", @@ -219,9 +216,7 @@ void CheckCondition::assignIfError(const Token *tok1, const Token *tok2, const s void CheckCondition::mismatchingBitAndError(const Token *tok1, const MathLib::bigint num1, const Token *tok2, const MathLib::bigint num2) { - std::list locations; - locations.push_back(tok1); - locations.push_back(tok2); + std::list locations = { tok1, tok2 }; std::ostringstream msg; msg << "Mismatching bitmasks. Result is always 0 (" @@ -687,9 +682,10 @@ void CheckCondition::oppositeInnerConditionError(const Token *tok1, const Token* { const std::string s1(tok1 ? tok1->expressionString() : "x"); const std::string s2(tok2 ? tok2->expressionString() : "!x"); - ErrorPath errorPath; - errorPath.push_back(ErrorPathItem(tok1, "outer condition: " + s1)); - errorPath.push_back(ErrorPathItem(tok2, "opposite inner condition: " + s2)); + ErrorPath errorPath = { + ErrorPathItem(tok1, "outer condition: " + s1), + ErrorPathItem(tok2, "opposite inner condition: " + s2) + }; const std::string msg("Opposite inner 'if' condition leads to a dead code block.\n" "Opposite inner 'if' condition leads to a dead code block (outer condition is '" + s1 + "' and inner condition is '" + s2 + "')."); reportError(errorPath, Severity::warning, "oppositeInnerCondition", msg, CWE398, false); @@ -699,9 +695,10 @@ void CheckCondition::identicalInnerConditionError(const Token *tok1, const Token { const std::string s1(tok1 ? tok1->expressionString() : "x"); const std::string s2(tok2 ? tok2->expressionString() : "x"); - ErrorPath errorPath; - errorPath.push_back(ErrorPathItem(tok1, "outer condition: " + s1)); - errorPath.push_back(ErrorPathItem(tok2, "identical inner condition: " + s2)); + ErrorPath errorPath = { + ErrorPathItem(tok1, "outer condition: " + s1), + ErrorPathItem(tok2, "identical inner condition: " + s2) + }; const std::string msg("Identical inner 'if' condition is always true.\n" "Identical inner 'if' condition is always true (outer condition is '" + s1 + "' and inner condition is '" + s2 + "')."); reportError(errorPath, Severity::warning, "identicalInnerCondition", msg, CWE398, false); @@ -710,9 +707,10 @@ void CheckCondition::identicalInnerConditionError(const Token *tok1, const Token void CheckCondition::identicalConditionAfterEarlyExitError(const Token *cond1, const Token* cond2) { const std::string cond(cond1 ? cond1->expressionString() : "x"); - ErrorPath errorPath; - errorPath.push_back(ErrorPathItem(cond1, "first condition")); - errorPath.push_back(ErrorPathItem(cond2, "second condition")); + ErrorPath errorPath = { + ErrorPathItem(cond1, "first condition"), + ErrorPathItem(cond2, "second condition") + }; reportError(errorPath, Severity::warning, "identicalConditionAfterEarlyExit", "Identical condition '" + cond + "', second condition is always false", CWE398, false); } diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fa7113b4b..5a716d064 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2860,9 +2860,7 @@ void CheckOther::checkFuncArgNamesDifferent() void CheckOther::funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition) { - std::list tokens; - tokens.push_back(declaration); - tokens.push_back(definition); + std::list tokens = { declaration,definition }; reportError(tokens, Severity::style, "funcArgNamesDifferent", "$symbol:" + functionName + "\n" "Function '$symbol' argument " + MathLib::toString(index + 1) + " names different: declaration '" + @@ -2875,9 +2873,10 @@ void CheckOther::funcArgOrderDifferent(const std::string & functionName, const std::vector & declarations, const std::vector & definitions) { - std::list tokens; - tokens.push_back(declarations.size() ? declarations[0] ? declarations[0] : declaration : nullptr); - tokens.push_back(definitions.size() ? definitions[0] ? definitions[0] : definition : nullptr); + std::list tokens = { + declarations.size() ? declarations[0] ? declarations[0] : declaration : nullptr, + definitions.size() ? definitions[0] ? definitions[0] : definition : nullptr + }; std::string msg = "$symbol:" + functionName + "\nFunction '$symbol' argument order different: declaration '"; for (std::size_t i = 0; i < declarations.size(); ++i) { if (i != 0) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index ca87a53ed..f013c2cfc 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -67,9 +67,7 @@ void CheckStl::iteratorsError(const Token *tok, const std::string &container1, c void CheckStl::dereferenceErasedError(const Token *erased, const Token* deref, const std::string &itername, bool inconclusive) { if (erased) { - std::list callstack; - callstack.push_back(deref); - callstack.push_back(erased); + std::list callstack = { deref, erased }; reportError(callstack, Severity::error, "eraseDereference", "$symbol:" + itername + "\n" "Iterator '$symbol' used after element has been erased.\n" @@ -1028,9 +1026,7 @@ void CheckStl::missingComparison() void CheckStl::missingComparisonError(const Token *incrementToken1, const Token *incrementToken2) { - std::list callstack; - callstack.push_back(incrementToken1); - callstack.push_back(incrementToken2); + std::list callstack = { incrementToken1,incrementToken2 }; std::ostringstream errmsg; errmsg << "Missing bounds check for extra iterator increment in loop.\n" diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 8aef730f8..612b353f3 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -166,8 +166,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin if (err) { const ErrorLogger::ErrorMessage::FileLocation loc1(it->location.file(), it->location.line); - std::list callstack; - callstack.push_back(loc1); + std::list callstack(1, loc1); ErrorLogger::ErrorMessage errmsg(callstack, "", @@ -476,8 +475,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg if (_settings.isEnabled(Settings::INFORMATION)) { const ErrorLogger::ErrorMessage::FileLocation loc1(filename, 0); - std::list callstack; - callstack.push_back(loc1); + std::list callstack(1, loc1); ErrorLogger::ErrorMessage errmsg(callstack, emptyString, diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b5161457a..0d6f3ccc3 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -92,8 +92,7 @@ static void execute(const Token *expr, static void bailoutInternal(TokenList *tokenlist, ErrorLogger *errorLogger, const Token *tok, const std::string &what, const std::string &file, int line, const std::string &function) { - std::list callstack; - callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(tok, tokenlist)); + std::list callstack(1, ErrorLogger::ErrorMessage::FileLocation(tok, tokenlist)); ErrorLogger::ErrorMessage errmsg(callstack, tokenlist->getSourceFilePath(), Severity::debug, Path::stripDirectoryPart(file) + ":" + MathLib::toString(line) + ":" + function + " bailout: " + what, "valueFlowBailout", false); errorLogger->reportErr(errmsg);