Skip to content

Commit

Permalink
reduced unnecessary usage of emptyString (#7229)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Jan 22, 2025
1 parent 853b0c5 commit 06e7663
Show file tree
Hide file tree
Showing 23 changed files with 100 additions and 109 deletions.
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
}

if (!settings.checkConfiguration) {
cppcheck.tooManyConfigsError(emptyString,0U);
cppcheck.tooManyConfigsError("",0U);
}

stdLogger.writeCheckersReport();
Expand Down
3 changes: 1 addition & 2 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#if !defined(WIN32) && !defined(__MINGW32__)

#include "config.h"
#include "cppcheck.h"
#include "errorlogger.h"
#include "errortypes.h"
Expand Down Expand Up @@ -404,7 +403,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
std::list<ErrorMessage::FileLocation> locations;
locations.emplace_back(childname, 0, 0);
const ErrorMessage errmsg(std::move(locations),
emptyString,
"",
Severity::error,
"Internal error: " + msg,
"cppcheckError",
Expand Down
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3794,7 +3794,7 @@ void CheckClass::getErrorMessages(ErrorLogger *errorLogger, const Settings *sett
c.uninitVarError(nullptr, false, Function::eConstructor, "classname", "varname", true, false);
c.uninitVarError(nullptr, true, Function::eConstructor, "classname", "varnamepriv", true, false);
c.missingMemberCopyError(nullptr, Function::eConstructor, "classname", "varnamepriv");
c.operatorEqVarError(nullptr, "classname", emptyString, false);
c.operatorEqVarError(nullptr, "classname", "", false);
c.unusedPrivateFunctionError(nullptr, "classname", "funcname");
c.memsetError(nullptr, "memfunc", "classname", "class");
c.memsetErrorReference(nullptr, "memfunc", "class");
Expand Down
2 changes: 1 addition & 1 deletion lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ void CheckCondition::getErrorMessages(ErrorLogger *errorLogger, const Settings *
{
CheckCondition c(nullptr, settings, errorLogger);

c.assignIfError(nullptr, nullptr, emptyString, false);
c.assignIfError(nullptr, nullptr, "", false);
c.badBitmaskCheckError(nullptr);
c.comparisonError(nullptr, "&", 6, "==", 1, false);
c.duplicateConditionError(nullptr, nullptr, ErrorPath{});
Expand Down
2 changes: 1 addition & 1 deletion lib/checknullpointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CPPCHECKLIB CheckNullPointer : public Check {
void nullPointerError(const Token *tok) {
ValueFlow::Value v(0);
v.setKnown();
nullPointerError(tok, emptyString, &v, false);
nullPointerError(tok, "", &v, false);
}
void nullPointerError(const Token *tok, const std::string &varname, const ValueFlow::Value* value, bool inconclusive);

Expand Down
4 changes: 2 additions & 2 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3376,8 +3376,8 @@ void CheckStl::getErrorMessages(ErrorLogger* errorLogger, const Settings* settin
c.uselessCallsRemoveError(nullptr, "remove");
c.dereferenceInvalidIteratorError(nullptr, "i");
c.eraseIteratorOutOfBoundsError(nullptr, nullptr);
c.useStlAlgorithmError(nullptr, emptyString);
c.knownEmptyContainerError(nullptr, emptyString);
c.useStlAlgorithmError(nullptr, "");
c.knownEmptyContainerError(nullptr, "");
c.globalLockGuardError(nullptr);
c.localMutexError(nullptr);
}
4 changes: 2 additions & 2 deletions lib/checkunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static void staticFunctionError(ErrorLogger& errorLogger,
locationList.back().fileIndex = fileIndex;
}

const ErrorMessage errmsg(std::move(locationList), emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' should have static linkage since it is not used outside of its translation unit.", "staticFunction", Certainty::normal);
const ErrorMessage errmsg(std::move(locationList), "", Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' should have static linkage since it is not used outside of its translation unit.", "staticFunction", Certainty::normal);
errorLogger.reportErr(errmsg);
}

Expand Down Expand Up @@ -412,7 +412,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger& errorLogger,
locationList.back().fileIndex = fileIndex;
}

const ErrorMessage errmsg(std::move(locationList), emptyString, Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal);
const ErrorMessage errmsg(std::move(locationList), "", Severity::style, "$symbol:" + funcname + "\nThe function '$symbol' is never used.", "unusedFunction", CWE561, Certainty::normal);
errorLogger.reportErr(errmsg);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/checkunusedfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CPPCHECKLIB CheckUnusedFunctions {
static void analyseWholeProgram(const Settings &settings, ErrorLogger& errorLogger, const std::string &buildDir);

static void getErrorMessages(ErrorLogger &errorLogger) {
unusedFunctionError(errorLogger, emptyString, 0, 0, "funcName");
unusedFunctionError(errorLogger, "", 0, 0, "funcName");
}

// Return true if an error is reported.
Expand Down
30 changes: 15 additions & 15 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static std::string getDumpFileName(const Settings& settings, const std::string&
extension = "." + std::to_string(settings.pid) + ".dump";

if (!settings.dump && !settings.buildDir.empty())
return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, filename, emptyString) + extension;
return AnalyzerInformation::getAnalyzerInfoFile(settings.buildDir, filename, "") + extension;
return filename + extension;
}

Expand Down Expand Up @@ -658,7 +658,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
mErrorLogger.reportOut(std::string("Checking ") + file.spath() + " ...", Color::FgGreen);

// TODO: get language from FileWithDetails object
const std::string analyzerInfo = mSettings.buildDir.empty() ? std::string() : AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, file.spath(), emptyString);
const std::string analyzerInfo = mSettings.buildDir.empty() ? std::string() : AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, file.spath(), "");
const std::string clangcmd = analyzerInfo + ".clang-cmd";
const std::string clangStderr = analyzerInfo + ".clang-stderr";
const std::string clangAst = analyzerInfo + ".clang-ast";
Expand Down Expand Up @@ -773,13 +773,13 @@ unsigned int CppCheck::check(const FileWithDetails &file)
if (mSettings.clang)
return checkClang(file);

return checkFile(file, emptyString);
return checkFile(file, "");
}

unsigned int CppCheck::check(const FileWithDetails &file, const std::string &content)
{
std::istringstream iss(content);
return checkFile(file, emptyString, &iss);
return checkFile(file, "", &iss);
}

unsigned int CppCheck::check(const FileSettings &fs)
Expand Down Expand Up @@ -1298,7 +1298,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
ErrorMessage::FileLocation loc1(filename, 0, 0);

ErrorMessage errmsg({std::move(loc1)},
emptyString,
"",
Severity::error,
fullmsg,
"internalError",
Expand Down Expand Up @@ -1333,7 +1333,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation
if (mSettings.debugwarnings) {
ErrorMessage::FileLocation loc(tokenizer.list.getFiles()[0], 0, 0);
ErrorMessage errmsg({std::move(loc)},
emptyString,
"",
Severity::debug,
"Checks maximum time exceeded",
"checksMaxTime",
Expand Down Expand Up @@ -1564,7 +1564,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
if (pcreCompileErrorStr) {
const std::string msg = "pcre_compile failed: " + std::string(pcreCompileErrorStr);
const ErrorMessage errmsg(std::list<ErrorMessage::FileLocation>(),
emptyString,
"",
Severity::error,
msg,
"pcre_compile",
Expand All @@ -1585,7 +1585,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
if (pcreStudyErrorStr) {
const std::string msg = "pcre_study failed: " + std::string(pcreStudyErrorStr);
const ErrorMessage errmsg(std::list<ErrorMessage::FileLocation>(),
emptyString,
"",
Severity::error,
msg,
"pcre_study",
Expand All @@ -1608,7 +1608,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
const std::string errorMessage = pcreErrorCodeToString(pcreExecRet);
if (!errorMessage.empty()) {
const ErrorMessage errmsg(std::list<ErrorMessage::FileLocation>(),
emptyString,
"",
Severity::error,
std::string("pcre_exec failed: ") + errorMessage,
"pcre_exec",
Expand Down Expand Up @@ -1843,7 +1843,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfCo


ErrorMessage errmsg(std::move(loclist),
emptyString,
"",
Severity::information,
msg.str(),
"toomanyconfigs", CWE398,
Expand All @@ -1865,7 +1865,7 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
}

ErrorMessage errmsg(std::move(loclist),
emptyString,
"",
Severity::information,
"The configuration '" + configuration + "' was not checked because its code equals another one.",
"purgedConfiguration",
Expand All @@ -1882,9 +1882,9 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
s.addEnabled("all");

CppCheck cppcheck(errorlogger, true, nullptr);
cppcheck.purgedConfigurationMessage(emptyString,emptyString);
cppcheck.purgedConfigurationMessage("","");
cppcheck.mTooManyConfigs = true;
cppcheck.tooManyConfigsError(emptyString,0U);
cppcheck.tooManyConfigsError("",0U);
// TODO: add functions to get remaining error messages

// call all "getErrorMessages" in all registered Check classes
Expand Down Expand Up @@ -1913,7 +1913,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)

const std::string args = "-quiet -checks=*,-clang-analyzer-*,-llvm* \"" + fileSettings.filename() + "\" -- " + allIncludes + allDefines;
std::string output;
if (const int exitcode = mExecuteCommand(exe, split(args), emptyString, output)) {
if (const int exitcode = mExecuteCommand(exe, split(args), "", output)) {
std::cerr << "Failed to execute '" << exe << "' (exitcode: " << std::to_string(exitcode) << ")" << std::endl;
return;
}
Expand All @@ -1923,7 +1923,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
std::string line;

if (!mSettings.buildDir.empty()) {
const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.filename(), emptyString);
const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, fileSettings.filename(), "");
std::ofstream fcmd(analyzerInfoFile + ".clang-tidy-cmd");
fcmd << istr.str();
}
Expand Down
10 changes: 5 additions & 5 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ ImportProject::Type ImportProject::import(const std::string &filename, Settings
} else if (endsWith(filename, ".vcxproj")) {
std::map<std::string, std::string, cppcheck::stricmp> variables;
std::vector<SharedItemsProject> sharedItemsProjects;
if (importVcxproj(filename, variables, emptyString, fileFilters, sharedItemsProjects)) {
if (importVcxproj(filename, variables, "", fileFilters, sharedItemsProjects)) {
setRelativePaths(filename);
return ImportProject::Type::VS_VCXPROJ;
}
Expand Down Expand Up @@ -462,7 +462,7 @@ bool ImportProject::importSln(std::istream &istr, const std::string &path, const
if (!Path::isAbsolute(vcxproj))
vcxproj = path + vcxproj;
vcxproj = Path::fromNativeSeparators(std::move(vcxproj));
if (!importVcxproj(vcxproj, variables, emptyString, fileFilters, sharedItemsProjects)) {
if (!importVcxproj(vcxproj, variables, "", fileFilters, sharedItemsProjects)) {
printError("failed to load '" + vcxproj + "' from Visual Studio solution");
return false;
}
Expand Down Expand Up @@ -1311,21 +1311,21 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
suppressions.push_back(std::move(s));
}
} else if (strcmp(name, CppcheckXml::VSConfigurationElementName) == 0)
guiProject.checkVsConfigs = readXmlStringList(node, emptyString, CppcheckXml::VSConfigurationName, nullptr);
guiProject.checkVsConfigs = readXmlStringList(node, "", CppcheckXml::VSConfigurationName, nullptr);
else if (strcmp(name, CppcheckXml::PlatformElementName) == 0)
guiProject.platform = empty_if_null(node->GetText());
else if (strcmp(name, CppcheckXml::AnalyzeAllVsConfigsElementName) == 0)
guiProject.analyzeAllVsConfigs = empty_if_null(node->GetText());
else if (strcmp(name, CppcheckXml::Parser) == 0)
temp.clang = true;
else if (strcmp(name, CppcheckXml::AddonsElementName) == 0) {
const auto& addons = readXmlStringList(node, emptyString, CppcheckXml::AddonElementName, nullptr);
const auto& addons = readXmlStringList(node, "", CppcheckXml::AddonElementName, nullptr);
temp.addons.insert(addons.cbegin(), addons.cend());
}
else if (strcmp(name, CppcheckXml::TagsElementName) == 0)
node->Attribute(CppcheckXml::TagElementName); // FIXME: Write some warning
else if (strcmp(name, CppcheckXml::ToolsElementName) == 0) {
const std::list<std::string> toolList = readXmlStringList(node, emptyString, CppcheckXml::ToolElementName, nullptr);
const std::list<std::string> toolList = readXmlStringList(node, "", CppcheckXml::ToolElementName, nullptr);
for (const std::string &toolName : toolList) {
if (toolName == CppcheckXml::ClangTidy)
temp.clangTidy = true;
Expand Down
12 changes: 6 additions & 6 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ std::list<Directive> Preprocessor::createDirectives(const simplecpp::TokenList &
continue;
if (tok->next && tok->next->str() == "endfile")
continue;
Directive directive(tok->location, emptyString);
Directive directive(tok->location, "");
for (const simplecpp::Token *tok2 = tok; tok2 && tok2->location.line == directive.linenr; tok2 = tok2->next) {
if (tok2->comment)
continue;
Expand Down Expand Up @@ -691,7 +691,7 @@ static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cf

splitcfg(mSettings.userDefines, dui.defines, "1");
if (!cfg.empty())
splitcfg(cfg, dui.defines, emptyString);
splitcfg(cfg, dui.defines, "");

for (const std::string &def : mSettings.library.defines()) {
const std::string::size_type pos = def.find_first_of(" (");
Expand Down Expand Up @@ -769,7 +769,7 @@ void Preprocessor::handleErrors(const simplecpp::OutputList& outputList, bool th

bool Preprocessor::loadFiles(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files)
{
const simplecpp::DUI dui = createDUI(mSettings, emptyString, files[0]);
const simplecpp::DUI dui = createDUI(mSettings, "", files[0]);

simplecpp::OutputList outputList;
mTokenLists = simplecpp::load(rawtokens, files, dui, &outputList);
Expand Down Expand Up @@ -924,9 +924,9 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &settings)
{
Preprocessor preprocessor(settings, errorLogger);
preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader);
preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader);
preprocessor.error(emptyString, 1, "#error message"); // #error ..
preprocessor.missingInclude("", 1, "", UserHeader);
preprocessor.missingInclude("", 1, "", SystemHeader);
preprocessor.error("", 1, "#error message"); // #error ..
}

void Preprocessor::dump(std::ostream &out) const
Expand Down
2 changes: 1 addition & 1 deletion lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ bool SuppressionList::reportUnmatchedSuppressions(const std::list<SuppressionLis
std::list<::ErrorMessage::FileLocation> callStack;
if (!s.fileName.empty())
callStack.emplace_back(s.fileName, s.lineNumber, 0);
errorLogger.reportErr(::ErrorMessage(std::move(callStack), emptyString, Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal));
errorLogger.reportErr(::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, "unmatchedSuppression", Certainty::normal));
err = true;
}
return err;
Expand Down
4 changes: 2 additions & 2 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
if (mSettings.debugwarnings) {
ErrorMessage::FileLocation loc(mTokenList.getFiles()[0], 0, 0);
ErrorMessage errmsg({std::move(loc)},
emptyString,
"",
Severity::debug,
"Template instantiation maximum time exceeded",
"templateMaxTime",
Expand Down Expand Up @@ -3251,7 +3251,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
if (mSettings.debugwarnings) {
ErrorMessage::FileLocation loc(mTokenList.getFiles()[0], 0, 0);
ErrorMessage errmsg({std::move(loc)},
emptyString,
"",
Severity::debug,
"Template instantiation maximum time exceeded",
"templateMaxTime",
Expand Down
2 changes: 1 addition & 1 deletion lib/templatesimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class CPPCHECKLIB TemplateSimplifier {
void printOut(
const TokenAndName &tokenAndName,
const std::string &indent = " ") const;
void printOut(const std::string &text = emptyString) const;
void printOut(const std::string &text = "") const;

Tokenizer &mTokenizer;
TokenList &mTokenList;
Expand Down
8 changes: 4 additions & 4 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ void Tokenizer::simplifyTypedefCpp()
if (mSettings.debugwarnings) {
ErrorMessage::FileLocation loc(list.getFiles()[0], 0, 0);
ErrorMessage errmsg({std::move(loc)},
emptyString,
"",
Severity::debug,
"Typedef simplification instantiation maximum time exceeded",
"typedefMaxTime",
Expand Down Expand Up @@ -10945,7 +10945,7 @@ void Tokenizer::getErrorMessages(ErrorLogger& errorLogger, const Settings& setti
Tokenizer tokenizer(settings, errorLogger);
tokenizer.invalidConstFunctionTypeError(nullptr);
// checkLibraryNoReturn
tokenizer.unhandled_macro_class_x_y(nullptr, emptyString, emptyString, emptyString, emptyString);
tokenizer.macroWithSemicolonError(nullptr, emptyString);
tokenizer.unhandledCharLiteral(nullptr, emptyString);
tokenizer.unhandled_macro_class_x_y(nullptr, "", "", "", "");
tokenizer.macroWithSemicolonError(nullptr, "");
tokenizer.unhandledCharLiteral(nullptr, "");
}
Loading

0 comments on commit 06e7663

Please sign in to comment.