Refactorization: Avoid construction of empty strings by using emptyString

This commit is contained in:
PKEuS 2017-03-01 10:50:50 +01:00
parent d501e488ca
commit 2f0db369f0
12 changed files with 30 additions and 30 deletions

View File

@ -1642,7 +1642,7 @@ void CheckClass::virtualDestructor()
}
for (std::list<const Function *>::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)

View File

@ -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");

View File

@ -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);

View File

@ -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..

View File

@ -75,11 +75,11 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string>
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<std::string>
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<std::string>
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;

View File

@ -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");
}
/**

View File

@ -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)

View File

@ -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;

View File

@ -159,7 +159,7 @@ void ImportProject::import(const std::string &filename)
importSln(fin,path);
} else if (filename.find(".vcxproj") != std::string::npos) {
std::map<std::string, std::string> variables;
importVcxproj(filename, variables, "");
importVcxproj(filename, variables, emptyString);
}
}

View File

@ -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);

View File

@ -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<std::string>::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<std::string> &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

View File

@ -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<std::string, const Function *>::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<std::string, const Function *>::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<Function *>(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<std::string, const Function *>::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;