From 2f0db369f0170adf4e90dfe67e79664df669392e Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 1 Mar 2017 10:50:50 +0100 Subject: [PATCH] Refactorization: Avoid construction of empty strings by using emptyString --- lib/checkclass.cpp | 2 +- lib/checkclass.h | 2 +- lib/checkcondition.h | 2 +- lib/checkmemoryleak.cpp | 2 +- lib/checkuninitvar.cpp | 14 +++++++------- lib/checkunusedfunctions.h | 2 +- lib/cppcheck.cpp | 4 ++-- lib/errorlogger.cpp | 6 +++--- lib/importproject.cpp | 2 +- lib/library.cpp | 2 +- lib/preprocessor.cpp | 14 +++++++------- lib/symboldatabase.cpp | 8 ++++---- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index ce62be290..9694827ec 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1642,7 +1642,7 @@ void CheckClass::virtualDestructor() } for (std::list::const_iterator i = inconclusiveErrors.begin(); i != inconclusiveErrors.end(); ++i) - virtualDestructorError((*i)->tokenDef, (*i)->name(), "", true); + virtualDestructorError((*i)->tokenDef, (*i)->name(), emptyString, true); } void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived, bool inconclusive) diff --git a/lib/checkclass.h b/lib/checkclass.h index 5fe5742fe..a9e55b372 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -176,7 +176,7 @@ private: c.copyConstructorShallowCopyError(nullptr, "var"); c.noCopyConstructorError(nullptr, "class", false); c.uninitVarError(nullptr, "classname", "varname", false); - c.operatorEqVarError(nullptr, "classname", "", false); + c.operatorEqVarError(nullptr, "classname", emptyString, false); c.unusedPrivateFunctionError(nullptr, "classname", "funcname"); c.memsetError(nullptr, "memfunc", "classname", "class"); c.memsetErrorReference(nullptr, "memfunc", "class"); diff --git a/lib/checkcondition.h b/lib/checkcondition.h index 32aca0e58..5fe24b47d 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -131,7 +131,7 @@ private: void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckCondition c(nullptr, settings, errorLogger); - c.assignIfError(nullptr, 0, "", false); + c.assignIfError(nullptr, 0, emptyString, false); c.badBitmaskCheckError(nullptr); c.comparisonError(nullptr, "&", 6, "==", 1, false); c.multiConditionError(nullptr,1); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 22051a671..035c0f81a 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2198,7 +2198,7 @@ void CheckMemoryLeakInFunction::check() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; if (!scope->hasInlineOrLambdaFunction()) - checkScope(scope->classStart->next(), "", 0, scope->functionOf != nullptr, 1); + checkScope(scope->classStart->next(), emptyString, 0, scope->functionOf != nullptr, 1); } // Check variables.. diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index a6cde627a..ca0e07a66 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -75,11 +75,11 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set continue; if (Token::Match(i->nameToken(), "%name% =")) { // Variable is initialized, but Rhs might be not - checkRhs(i->nameToken(), *i, NO_ALLOC, 0U, ""); + checkRhs(i->nameToken(), *i, NO_ALLOC, 0U, emptyString); continue; } if (Token::Match(i->nameToken(), "%name% ) (") && Token::simpleMatch(i->nameToken()->linkAt(2), ") =")) { // Function pointer is initialized, but Rhs might be not - checkRhs(i->nameToken()->linkAt(2)->next(), *i, NO_ALLOC, 0U, ""); + checkRhs(i->nameToken()->linkAt(2)->next(), *i, NO_ALLOC, 0U, emptyString); continue; } @@ -108,17 +108,17 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set continue; if (tok->astParent() && Token::simpleMatch(tok->astParent()->previous(), "for (") && - checkLoopBody(tok->astParent()->link()->next(), *i, i->isArray() ? ARRAY : NO_ALLOC, "", true)) + checkLoopBody(tok->astParent()->link()->next(), *i, i->isArray() ? ARRAY : NO_ALLOC, emptyString, true)) continue; if (i->isArray()) { Alloc alloc = ARRAY; - checkScopeForVariable(tok, *i, nullptr, nullptr, &alloc, ""); + checkScopeForVariable(tok, *i, nullptr, nullptr, &alloc, emptyString); continue; } if (stdtype || i->isPointer()) { Alloc alloc = NO_ALLOC; - checkScopeForVariable(tok, *i, nullptr, nullptr, &alloc, ""); + checkScopeForVariable(tok, *i, nullptr, nullptr, &alloc, emptyString); } if (i->type()) checkStruct(tok, *i); @@ -136,7 +136,7 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set checkStruct(tok, *arg); else if (arg->typeStartToken()->isStandardType() || arg->typeStartToken()->isEnumType()) { Alloc alloc = NO_ALLOC; - checkScopeForVariable(tok->next(), *arg, nullptr, nullptr, &alloc, ""); + checkScopeForVariable(tok->next(), *arg, nullptr, nullptr, &alloc, emptyString); } } } @@ -698,7 +698,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var else { if (tok->strAt(1) == "=") - checkRhs(tok, var, *alloc, number_of_if, ""); + checkRhs(tok, var, *alloc, number_of_if, emptyString); // assume that variable is assigned return true; diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 8f834c86e..89d1ebb25 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -68,7 +68,7 @@ private: void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckUnusedFunctions c(nullptr, settings, errorLogger); - c.unusedFunctionError(errorLogger, "", 0, "funcName"); + c.unusedFunctionError(errorLogger, emptyString, 0, "funcName"); } /** diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 352f7d412..bb54c4ae4 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -73,13 +73,13 @@ const char * CppCheck::extraVersion() unsigned int CppCheck::check(const std::string &path) { std::ifstream fin(path.c_str()); - return processFile(path, "", fin); + return processFile(path, emptyString, fin); } unsigned int CppCheck::check(const std::string &path, const std::string &content) { std::istringstream iss(content); - return processFile(path, "", iss); + return processFile(path, emptyString, iss); } unsigned int CppCheck::check(const ImportProject::FileSettings &fs) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 40268032a..3af4a009f 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -394,15 +394,15 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string findAndReplace(result, "{id}", _id); findAndReplace(result, "{severity}", Severity::toString(_severity)); findAndReplace(result, "{message}", verbose ? _verboseMessage : _shortMessage); - findAndReplace(result, "{callstack}", _callStack.empty() ? "" : callStackToString(_callStack)); + findAndReplace(result, "{callstack}", _callStack.empty() ? emptyString : callStackToString(_callStack)); if (!_callStack.empty()) { std::ostringstream oss; oss << _callStack.back().line; findAndReplace(result, "{line}", oss.str()); findAndReplace(result, "{file}", _callStack.back().getfile()); } else { - findAndReplace(result, "{file}", ""); - findAndReplace(result, "{line}", ""); + findAndReplace(result, "{file}", emptyString); + findAndReplace(result, "{line}", emptyString); } return result; diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 569918fad..04ddecda0 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -159,7 +159,7 @@ void ImportProject::import(const std::string &filename) importSln(fin,path); } else if (filename.find(".vcxproj") != std::string::npos) { std::map variables; - importVcxproj(filename, variables, ""); + importVcxproj(filename, variables, emptyString); } } diff --git a/lib/library.cpp b/lib/library.cpp index 774a08659..298eeda57 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -489,7 +489,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) unknown_elements.insert(typenodename); } if (platform.empty()) { - const PlatformType * const type_ptr = platform_type(type_name, ""); + const PlatformType * const type_ptr = platform_type(type_name, emptyString); if (type_ptr) { if (*type_ptr == type) return Error(DUPLICATE_PLATFORM_TYPE, type_name); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 4873a6ab3..e33073b9b 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -138,7 +138,7 @@ void Preprocessor::setDirectives(const simplecpp::TokenList &tokens1) continue; if (tok->next && tok->next->str == "endfile") continue; - Directive directive(tok->location.file(), tok->location.line, ""); + Directive directive(tok->location.file(), tok->location.line, emptyString); for (const simplecpp::Token *tok2 = tok; tok2 && tok2->location.line == directive.linenr; tok2 = tok2->next) { if (tok2->comment) continue; @@ -473,7 +473,7 @@ static simplecpp::DUI createDUI(const Settings &_settings, const std::string &cf splitcfg(_settings.userDefines, dui.defines, "1"); if (!cfg.empty()) - splitcfg(cfg, dui.defines, ""); + splitcfg(cfg, dui.defines, emptyString); for (std::vector::const_iterator it = _settings.library.defines.begin(); it != _settings.library.defines.end(); ++it) { if (it->compare(0,8,"#define ")!=0) @@ -521,7 +521,7 @@ static bool hasErrors(const simplecpp::OutputList &outputList) void Preprocessor::loadFiles(const simplecpp::TokenList &rawtokens, std::vector &files) { - const simplecpp::DUI dui = createDUI(_settings, "", files[0]); + const simplecpp::DUI dui = createDUI(_settings, emptyString, files[0]); simplecpp::OutputList outputList; @@ -788,10 +788,10 @@ void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *se Settings settings2(*settings); Preprocessor preprocessor(settings2, errorLogger); settings2.checkConfiguration=true; - preprocessor.missingInclude("", 1, "", UserHeader); - preprocessor.missingInclude("", 1, "", SystemHeader); - preprocessor.validateCfgError("", 1, "X", "X"); - preprocessor.error("", 1, "#error message"); // #error .. + preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader); + preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader); + preprocessor.validateCfgError(emptyString, 1, "X", "X"); + preprocessor.error(emptyString, 1, "#error message"); // #error .. } void Preprocessor::dump(std::ostream &out) const diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 8b7b0689b..cc9dd691f 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -716,7 +716,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() else if (declEnd && declEnd->str() == ";") { bool newFunc = true; // Is this function already in the database? for (std::multimap::const_iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) { - if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), "", 0)) { + if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), emptyString, 0)) { newFunc = false; break; } @@ -1921,7 +1921,7 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co { Function* function = nullptr; for (std::multimap::iterator i = scope->functionMap.find(tok->str()); i != scope->functionMap.end() && i->first == tok->str(); ++i) { - if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), "", 0)) { + if (Function::argsMatch(scope, i->second->argDef->next(), argStart->next(), emptyString, 0)) { function = const_cast(i->second); break; } @@ -2997,7 +2997,7 @@ bool Function::isImplicitlyVirtual_rec(const ::Type* baseType, bool& safe) const } // check for matching function parameters - if (returnMatch && argsMatch(baseType->classScope, func->argDef, argDef, "", 0)) { + if (returnMatch && argsMatch(baseType->classScope, func->argDef, argDef, emptyString, 0)) { return true; } } @@ -4317,7 +4317,7 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n for (std::multimap::const_iterator it = ns->functionMap.find(func->str()); it != ns->functionMap.end() && it->first == func->str(); ++it) { - if (Function::argsMatch(ns, func->tokAt(2), it->second->argDef->next(), "", 0) && + if (Function::argsMatch(ns, func->tokAt(2), it->second->argDef->next(), emptyString, 0) && it->second->isDestructor() == destructor) { function = it->second; break;