diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 5da5b898e4cf..ca05d4cb96c6 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -1127,33 +1127,35 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a Settings::Rule rule; for (const tinyxml2::XMLElement *subnode = node->FirstChildElement(); subnode; subnode = subnode->NextSiblingElement()) { + const char * const subname = subnode->Name(); const char * const subtext = subnode->GetText(); - if (std::strcmp(subnode->Name(), "tokenlist") == 0) { + if (std::strcmp(subname, "tokenlist") == 0) { rule.tokenlist = empty_if_null(subtext); } - else if (std::strcmp(subnode->Name(), "pattern") == 0) { + else if (std::strcmp(subname, "pattern") == 0) { rule.pattern = empty_if_null(subtext); } - else if (std::strcmp(subnode->Name(), "message") == 0) { + else if (std::strcmp(subname, "message") == 0) { for (const tinyxml2::XMLElement *msgnode = subnode->FirstChildElement(); msgnode; msgnode = msgnode->NextSiblingElement()) { + const char * const msgname = msgnode->Name(); const char * const msgtext = msgnode->GetText(); - if (std::strcmp(msgnode->Name(), "severity") == 0) { + if (std::strcmp(msgname, "severity") == 0) { rule.severity = severityFromString(empty_if_null(msgtext)); } - else if (std::strcmp(msgnode->Name(), "id") == 0) { + else if (std::strcmp(msgname, "id") == 0) { rule.id = empty_if_null(msgtext); } - else if (std::strcmp(msgnode->Name(), "summary") == 0) { + else if (std::strcmp(msgname, "summary") == 0) { rule.summary = empty_if_null(msgtext); } else { - mLogger.printError("unable to load rule-file '" + ruleFile + "' - unknown element '" + msgnode->Name() + "' encountered in 'message'."); + mLogger.printError("unable to load rule-file '" + ruleFile + "' - unknown element '" + msgname + "' encountered in 'message'."); return Result::Fail; } } } else { - mLogger.printError("unable to load rule-file '" + ruleFile + "' - unknown element '" + subnode->Name() + "' encountered in 'rule'."); + mLogger.printError("unable to load rule-file '" + ruleFile + "' - unknown element '" + subname + "' encountered in 'rule'."); return Result::Fail; } } diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 144ae3109193..02b149a0b96c 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -968,9 +968,10 @@ Check::FileInfo * CheckBufferOverrun::loadFileInfoFromXml(const tinyxml2::XMLEle auto *fileInfo = new MyFileInfo; for (const tinyxml2::XMLElement *e = xmlElement->FirstChildElement(); e; e = e->NextSiblingElement()) { - if (e->Name() == arrayIndex) + const char* name = e->Name(); + if (name == arrayIndex) fileInfo->unsafeArrayIndex = CTU::loadUnsafeUsageListFromXml(e); - else if (e->Name() == pointerArith) + else if (name == pointerArith) fileInfo->unsafePointerArith = CTU::loadUnsafeUsageListFromXml(e); } diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index f538b3a35447..26db9129129c 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -427,11 +427,12 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo const char* functionName = e2->Attribute("functionName"); if (functionName == nullptr) continue; - if (std::strcmp(e2->Name(),"functioncall") == 0) { + const char* name = e2->Name(); + if (std::strcmp(name,"functioncall") == 0) { calls.insert(functionName); continue; } - if (std::strcmp(e2->Name(),"functiondecl") == 0) { + if (std::strcmp(name,"functiondecl") == 0) { const char* lineNumber = e2->Attribute("lineNumber"); if (lineNumber) { // cppcheck-suppress templateInstantiation - TODO: fix this - see #11631 diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 4f542bacf482..5df85a0fe50c 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -232,11 +232,12 @@ bool CTU::FileInfo::NestedCall::loadFromXml(const tinyxml2::XMLElement *xmlEleme void CTU::FileInfo::loadFromXml(const tinyxml2::XMLElement *xmlElement) { for (const tinyxml2::XMLElement *e = xmlElement->FirstChildElement(); e; e = e->NextSiblingElement()) { - if (std::strcmp(e->Name(), "function-call") == 0) { + const char* name = e->Name(); + if (std::strcmp(name, "function-call") == 0) { FunctionCall functionCall; if (functionCall.loadFromXml(e)) functionCalls.push_back(std::move(functionCall)); - } else if (std::strcmp(e->Name(), "nested-call") == 0) { + } else if (std::strcmp(name, "nested-call") == 0) { NestedCall nestedCall; if (nestedCall.loadFromXml(e)) nestedCalls.push_back(std::move(nestedCall)); diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 17c5a82c977f..06901a488ded 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -190,7 +190,8 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) hash = attr ? strToInt(attr) : 0; for (const tinyxml2::XMLElement *e = errmsg->FirstChildElement(); e; e = e->NextSiblingElement()) { - if (std::strcmp(e->Name(),"location")==0) { + const char* name = e->Name(); + if (std::strcmp(name,"location")==0) { const char *strfile = e->Attribute("file"); const char *strinfo = e->Attribute("info"); const char *strline = e->Attribute("line"); @@ -201,7 +202,7 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) const int line = strline ? strToInt(strline) : 0; const int column = strcolumn ? strToInt(strcolumn) : 0; callStack.emplace_front(file, info, line, column); - } else if (std::strcmp(e->Name(),"symbol")==0) { + } else if (std::strcmp(name,"symbol")==0) { mSymbolNames += e->GetText(); } } diff --git a/lib/importproject.cpp b/lib/importproject.cpp index e1caa25afbc7..ed3ec74858f7 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -486,9 +486,10 @@ namespace { const char * const text = e->GetText(); if (!text) continue; - if (std::strcmp(e->Name(),"Configuration")==0) + const char * ename = e->Name(); + if (std::strcmp(ename,"Configuration")==0) configuration = text; - else if (std::strcmp(e->Name(),"Platform")==0) { + else if (std::strcmp(ename,"Platform")==0) { platformStr = text; if (platformStr == "Win32") platform = Win32; @@ -511,19 +512,21 @@ namespace { if (condAttr) condition = condAttr; for (const tinyxml2::XMLElement *e1 = idg->FirstChildElement(); e1; e1 = e1->NextSiblingElement()) { - if (std::strcmp(e1->Name(), "ClCompile") == 0) { + const char* name = e1->Name(); + if (std::strcmp(name, "ClCompile") == 0) { enhancedInstructionSet = "StreamingSIMDExtensions2"; for (const tinyxml2::XMLElement *e = e1->FirstChildElement(); e; e = e->NextSiblingElement()) { const char * const text = e->GetText(); if (!text) continue; - if (std::strcmp(e->Name(), "PreprocessorDefinitions") == 0) + const char * const ename = e->Name(); + if (std::strcmp(ename, "PreprocessorDefinitions") == 0) preprocessorDefinitions = text; - else if (std::strcmp(e->Name(), "AdditionalIncludeDirectories") == 0) { + else if (std::strcmp(ename, "AdditionalIncludeDirectories") == 0) { if (!additionalIncludePaths.empty()) additionalIncludePaths += ';'; additionalIncludePaths += text; - } else if (std::strcmp(e->Name(), "LanguageStandard") == 0) { + } else if (std::strcmp(ename, "LanguageStandard") == 0) { if (std::strcmp(text, "stdcpp14") == 0) cppstd = Standards::CPP14; else if (std::strcmp(text, "stdcpp17") == 0) @@ -532,12 +535,12 @@ namespace { cppstd = Standards::CPP20; else if (std::strcmp(text, "stdcpplatest") == 0) cppstd = Standards::CPPLatest; - } else if (std::strcmp(e->Name(), "EnableEnhancedInstructionSet") == 0) { + } else if (std::strcmp(ename, "EnableEnhancedInstructionSet") == 0) { enhancedInstructionSet = text; } } } - else if (std::strcmp(e1->Name(), "Link") == 0) { + else if (std::strcmp(name, "Link") == 0) { for (const tinyxml2::XMLElement *e = e1->FirstChildElement(); e; e = e->NextSiblingElement()) { const char * const text = e->GetText(); if (!text) @@ -638,7 +641,7 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::mapAttribute("Label"); if (labelAttribute && std::strcmp(labelAttribute, "UserMacros") == 0) { for (const tinyxml2::XMLElement *propertyGroup = node->FirstChildElement(); propertyGroup; propertyGroup = propertyGroup->NextSiblingElement()) { - const std::string name(propertyGroup->Name()); + const char* name = propertyGroup->Name(); const char *text = empty_if_null(propertyGroup->GetText()); variables[name] = text; } @@ -677,7 +680,8 @@ static void loadVisualStudioProperties(const std::string &props, std::mapFirstChildElement(); node; node = node->NextSiblingElement()) { - if (std::strcmp(node->Name(), "ImportGroup") == 0) { + const char* name = node->Name(); + if (std::strcmp(name, "ImportGroup") == 0) { const char *labelAttribute = node->Attribute("Label"); if (labelAttribute == nullptr || std::strcmp(labelAttribute, "PropertySheets") != 0) continue; @@ -693,9 +697,9 @@ static void loadVisualStudioProperties(const std::string &props, std::mapName(),"PropertyGroup")==0) { + } else if (std::strcmp(name,"PropertyGroup")==0) { importPropertyGroup(node, variables, includePath, nullptr); - } else if (std::strcmp(node->Name(),"ItemDefinitionGroup")==0) { + } else if (std::strcmp(name,"ItemDefinitionGroup")==0) { itemDefinitionGroupList.emplace_back(node, additionalIncludeDirectories); } } @@ -724,7 +728,8 @@ bool ImportProject::importVcxproj(const std::string &filename, std::mapFirstChildElement(); node; node = node->NextSiblingElement()) { - if (std::strcmp(node->Name(), "ItemGroup") == 0) { + const char* name = node->Name(); + if (std::strcmp(name, "ItemGroup") == 0) { const char *labelAttribute = node->Attribute("Label"); if (labelAttribute && std::strcmp(labelAttribute, "ProjectConfigurations") == 0) { for (const tinyxml2::XMLElement *cfg = node->FirstChildElement(); cfg; cfg = cfg->NextSiblingElement()) { @@ -745,11 +750,11 @@ bool ImportProject::importVcxproj(const std::string &filename, std::mapName(), "ItemDefinitionGroup") == 0) { + } else if (std::strcmp(name, "ItemDefinitionGroup") == 0) { itemDefinitionGroupList.emplace_back(node, additionalIncludeDirectories); - } else if (std::strcmp(node->Name(), "PropertyGroup") == 0) { + } else if (std::strcmp(name, "PropertyGroup") == 0) { importPropertyGroup(node, variables, includePath, &useOfMfc); - } else if (std::strcmp(node->Name(), "ImportGroup") == 0) { + } else if (std::strcmp(name, "ImportGroup") == 0) { const char *labelAttribute = node->Attribute("Label"); if (labelAttribute && std::strcmp(labelAttribute, "PropertySheets") == 0) { for (const tinyxml2::XMLElement *e = node->FirstChildElement(); e; e = e->NextSiblingElement()) { @@ -842,7 +847,8 @@ bool ImportProject::importBcb6Prj(const std::string &projectFilename) std::string cflag1; for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { - if (std::strcmp(node->Name(), "FILELIST") == 0) { + const char* name = node->Name(); + if (std::strcmp(name, "FILELIST") == 0) { for (const tinyxml2::XMLElement *f = node->FirstChildElement(); f; f = f->NextSiblingElement()) { if (std::strcmp(f->Name(), "FILE") == 0) { const char *filename = f->Attribute("FILENAME"); @@ -850,23 +856,24 @@ bool ImportProject::importBcb6Prj(const std::string &projectFilename) compileList.emplace_back(filename); } } - } else if (std::strcmp(node->Name(), "MACROS") == 0) { + } else if (std::strcmp(name, "MACROS") == 0) { for (const tinyxml2::XMLElement *m = node->FirstChildElement(); m; m = m->NextSiblingElement()) { - if (std::strcmp(m->Name(), "INCLUDEPATH") == 0) { + const char* mname = m->Name(); + if (std::strcmp(mname, "INCLUDEPATH") == 0) { const char *v = m->Attribute("value"); if (v) includePath = v; - } else if (std::strcmp(m->Name(), "USERDEFINES") == 0) { + } else if (std::strcmp(mname, "USERDEFINES") == 0) { const char *v = m->Attribute("value"); if (v) userdefines = v; - } else if (std::strcmp(m->Name(), "SYSDEFINES") == 0) { + } else if (std::strcmp(mname, "SYSDEFINES") == 0) { const char *v = m->Attribute("value"); if (v) sysdefines = v; } } - } else if (std::strcmp(node->Name(), "OPTIONS") == 0) { + } else if (std::strcmp(name, "OPTIONS") == 0) { for (const tinyxml2::XMLElement *m = node->FirstChildElement(); m; m = m->NextSiblingElement()) { if (std::strcmp(m->Name(), "CFLAG1") == 0) { const char *v = m->Attribute("value"); @@ -1149,38 +1156,39 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti // TODO: this should support all available command-line options for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { - if (strcmp(node->Name(), CppcheckXml::RootPathName) == 0) { + const char* name = node->Name(); + if (strcmp(name, CppcheckXml::RootPathName) == 0) { if (node->Attribute(CppcheckXml::RootPathNameAttrib)) { temp.basePaths.push_back(joinRelativePath(path, node->Attribute(CppcheckXml::RootPathNameAttrib))); temp.relativePaths = true; } - } else if (strcmp(node->Name(), CppcheckXml::BuildDirElementName) == 0) + } else if (strcmp(name, CppcheckXml::BuildDirElementName) == 0) temp.buildDir = joinRelativePath(path, empty_if_null(node->GetText())); - else if (strcmp(node->Name(), CppcheckXml::IncludeDirElementName) == 0) + else if (strcmp(name, CppcheckXml::IncludeDirElementName) == 0) temp.includePaths = readXmlStringList(node, path, CppcheckXml::DirElementName, CppcheckXml::DirNameAttrib); - else if (strcmp(node->Name(), CppcheckXml::DefinesElementName) == 0) + else if (strcmp(name, CppcheckXml::DefinesElementName) == 0) temp.userDefines = join(readXmlStringList(node, "", CppcheckXml::DefineName, CppcheckXml::DefineNameAttrib), ";"); - else if (strcmp(node->Name(), CppcheckXml::UndefinesElementName) == 0) { + else if (strcmp(name, CppcheckXml::UndefinesElementName) == 0) { for (const std::string &u : readXmlStringList(node, "", CppcheckXml::UndefineName, nullptr)) temp.userUndefs.insert(u); - } else if (strcmp(node->Name(), CppcheckXml::ImportProjectElementName) == 0) { + } else if (strcmp(name, CppcheckXml::ImportProjectElementName) == 0) { const std::string t_str = empty_if_null(node->GetText()); if (!t_str.empty()) guiProject.projectFile = path + t_str; } - else if (strcmp(node->Name(), CppcheckXml::PathsElementName) == 0) + else if (strcmp(name, CppcheckXml::PathsElementName) == 0) paths = readXmlStringList(node, path, CppcheckXml::PathName, CppcheckXml::PathNameAttrib); - else if (strcmp(node->Name(), CppcheckXml::ExcludeElementName) == 0) + else if (strcmp(name, CppcheckXml::ExcludeElementName) == 0) guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::ExcludePathName, CppcheckXml::ExcludePathNameAttrib); - else if (strcmp(node->Name(), CppcheckXml::FunctionContracts) == 0) + else if (strcmp(name, CppcheckXml::FunctionContracts) == 0) ; - else if (strcmp(node->Name(), CppcheckXml::VariableContractsElementName) == 0) + else if (strcmp(name, CppcheckXml::VariableContractsElementName) == 0) ; - else if (strcmp(node->Name(), CppcheckXml::IgnoreElementName) == 0) + else if (strcmp(name, CppcheckXml::IgnoreElementName) == 0) guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::IgnorePathName, CppcheckXml::IgnorePathNameAttrib); - else if (strcmp(node->Name(), CppcheckXml::LibrariesElementName) == 0) + else if (strcmp(name, CppcheckXml::LibrariesElementName) == 0) guiProject.libraries = readXmlStringList(node, "", CppcheckXml::LibraryElementName, nullptr); - else if (strcmp(node->Name(), CppcheckXml::SuppressionsElementName) == 0) { + else if (strcmp(name, CppcheckXml::SuppressionsElementName) == 0) { for (const tinyxml2::XMLElement *child = node->FirstChildElement(); child; child = child->NextSiblingElement()) { if (strcmp(child->Name(), CppcheckXml::SuppressionElementName) != 0) continue; @@ -1194,72 +1202,73 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti s.hash = strToInt(default_if_null(child->Attribute("hash"), "0")); suppressions.push_back(std::move(s)); } - } else if (strcmp(node->Name(), CppcheckXml::VSConfigurationElementName) == 0) + } else if (strcmp(name, CppcheckXml::VSConfigurationElementName) == 0) guiProject.checkVsConfigs = readXmlStringList(node, emptyString, CppcheckXml::VSConfigurationName, nullptr); - else if (strcmp(node->Name(), CppcheckXml::PlatformElementName) == 0) + else if (strcmp(name, CppcheckXml::PlatformElementName) == 0) guiProject.platform = empty_if_null(node->GetText()); - else if (strcmp(node->Name(), CppcheckXml::AnalyzeAllVsConfigsElementName) == 0) + else if (strcmp(name, CppcheckXml::AnalyzeAllVsConfigsElementName) == 0) guiProject.analyzeAllVsConfigs = empty_if_null(node->GetText()); - else if (strcmp(node->Name(), CppcheckXml::Parser) == 0) + else if (strcmp(name, CppcheckXml::Parser) == 0) temp.clang = true; - else if (strcmp(node->Name(), CppcheckXml::AddonsElementName) == 0) { + else if (strcmp(name, CppcheckXml::AddonsElementName) == 0) { const auto& addons = readXmlStringList(node, emptyString, CppcheckXml::AddonElementName, nullptr); temp.addons.insert(addons.cbegin(), addons.cend()); } - else if (strcmp(node->Name(), CppcheckXml::TagsElementName) == 0) + else if (strcmp(name, CppcheckXml::TagsElementName) == 0) node->Attribute(CppcheckXml::TagElementName); // FIXME: Write some warning - else if (strcmp(node->Name(), CppcheckXml::ToolsElementName) == 0) { + else if (strcmp(name, CppcheckXml::ToolsElementName) == 0) { const std::list toolList = readXmlStringList(node, emptyString, CppcheckXml::ToolElementName, nullptr); for (const std::string &toolName : toolList) { if (toolName == CppcheckXml::ClangTidy) temp.clangTidy = true; } - } else if (strcmp(node->Name(), CppcheckXml::CheckHeadersElementName) == 0) + } else if (strcmp(name, CppcheckXml::CheckHeadersElementName) == 0) temp.checkHeaders = (strcmp(default_if_null(node->GetText(), ""), "true") == 0); - else if (strcmp(node->Name(), CppcheckXml::CheckLevelExhaustiveElementName) == 0) + else if (strcmp(name, CppcheckXml::CheckLevelExhaustiveElementName) == 0) checkLevelExhaustive = true; - else if (strcmp(node->Name(), CppcheckXml::CheckUnusedTemplatesElementName) == 0) + else if (strcmp(name, CppcheckXml::CheckUnusedTemplatesElementName) == 0) temp.checkUnusedTemplates = (strcmp(default_if_null(node->GetText(), ""), "true") == 0); - else if (strcmp(node->Name(), CppcheckXml::InlineSuppression) == 0) + else if (strcmp(name, CppcheckXml::InlineSuppression) == 0) temp.inlineSuppressions = (strcmp(default_if_null(node->GetText(), ""), "true") == 0); - else if (strcmp(node->Name(), CppcheckXml::MaxCtuDepthElementName) == 0) + else if (strcmp(name, CppcheckXml::MaxCtuDepthElementName) == 0) temp.maxCtuDepth = strToInt(default_if_null(node->GetText(), "2")); // TODO: bail out when missing? - else if (strcmp(node->Name(), CppcheckXml::MaxTemplateRecursionElementName) == 0) + else if (strcmp(name, CppcheckXml::MaxTemplateRecursionElementName) == 0) temp.maxTemplateRecursion = strToInt(default_if_null(node->GetText(), "100")); // TODO: bail out when missing? - else if (strcmp(node->Name(), CppcheckXml::CheckUnknownFunctionReturn) == 0) + else if (strcmp(name, CppcheckXml::CheckUnknownFunctionReturn) == 0) ; // TODO - else if (strcmp(node->Name(), Settings::SafeChecks::XmlRootName) == 0) { + else if (strcmp(name, Settings::SafeChecks::XmlRootName) == 0) { for (const tinyxml2::XMLElement *child = node->FirstChildElement(); child; child = child->NextSiblingElement()) { - if (strcmp(child->Name(), Settings::SafeChecks::XmlClasses) == 0) + const char* childname = child->Name(); + if (strcmp(childname, Settings::SafeChecks::XmlClasses) == 0) temp.safeChecks.classes = true; - else if (strcmp(child->Name(), Settings::SafeChecks::XmlExternalFunctions) == 0) + else if (strcmp(childname, Settings::SafeChecks::XmlExternalFunctions) == 0) temp.safeChecks.externalFunctions = true; - else if (strcmp(child->Name(), Settings::SafeChecks::XmlInternalFunctions) == 0) + else if (strcmp(childname, Settings::SafeChecks::XmlInternalFunctions) == 0) temp.safeChecks.internalFunctions = true; - else if (strcmp(child->Name(), Settings::SafeChecks::XmlExternalVariables) == 0) + else if (strcmp(childname, Settings::SafeChecks::XmlExternalVariables) == 0) temp.safeChecks.externalVariables = true; else { - printError("Unknown '" + std::string(Settings::SafeChecks::XmlRootName) + "' element '" + std::string(child->Name()) + "' in Cppcheck project file"); + printError("Unknown '" + std::string(Settings::SafeChecks::XmlRootName) + "' element '" + childname + "' in Cppcheck project file"); return false; } } - } else if (strcmp(node->Name(), CppcheckXml::TagWarningsElementName) == 0) + } else if (strcmp(name, CppcheckXml::TagWarningsElementName) == 0) ; // TODO // Cppcheck Premium features - else if (strcmp(node->Name(), CppcheckXml::BughuntingElementName) == 0) + else if (strcmp(name, CppcheckXml::BughuntingElementName) == 0) temp.premiumArgs += " --bughunting"; - else if (strcmp(node->Name(), CppcheckXml::CertIntPrecisionElementName) == 0) + else if (strcmp(name, CppcheckXml::CertIntPrecisionElementName) == 0) temp.premiumArgs += std::string(" --cert-c-int-precision=") + default_if_null(node->GetText(), "0"); - else if (strcmp(node->Name(), CppcheckXml::CodingStandardsElementName) == 0) { + else if (strcmp(name, CppcheckXml::CodingStandardsElementName) == 0) { for (const tinyxml2::XMLElement *child = node->FirstChildElement(); child; child = child->NextSiblingElement()) { if (strcmp(child->Name(), CppcheckXml::CodingStandardElementName) == 0 && child->GetText()) temp.premiumArgs += std::string(" --") + child->GetText(); } } - else if (strcmp(node->Name(), CppcheckXml::ProjectNameElementName) == 0) + else if (strcmp(name, CppcheckXml::ProjectNameElementName) == 0) ; // no-op else { - printError("Unknown element '" + std::string(node->Name()) + "' in Cppcheck project file"); + printError("Unknown element '" + std::string(name) + "' in Cppcheck project file"); return false; } } diff --git a/lib/platform.cpp b/lib/platform.cpp index f54b9110afe7..34a379121a4a 100644 --- a/lib/platform.cpp +++ b/lib/platform.cpp @@ -250,37 +250,39 @@ bool Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc) bool error = false; for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { - if (std::strcmp(node->Name(), "default-sign") == 0) { + const char* name = node->Name(); + if (std::strcmp(name, "default-sign") == 0) { const char* str = node->GetText(); if (str) defaultSign = *str; else error = true; - } else if (std::strcmp(node->Name(), "char_bit") == 0) + } else if (std::strcmp(name, "char_bit") == 0) char_bit = xmlTextAsUInt(node, error); - else if (std::strcmp(node->Name(), "sizeof") == 0) { + else if (std::strcmp(name, "sizeof") == 0) { for (const tinyxml2::XMLElement *sz = node->FirstChildElement(); sz; sz = sz->NextSiblingElement()) { - if (std::strcmp(sz->Name(), "short") == 0) + const char* szname = sz->Name(); + if (std::strcmp(szname, "short") == 0) sizeof_short = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "bool") == 0) + else if (std::strcmp(szname, "bool") == 0) sizeof_bool = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "int") == 0) + else if (std::strcmp(szname, "int") == 0) sizeof_int = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "long") == 0) + else if (std::strcmp(szname, "long") == 0) sizeof_long = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "long-long") == 0) + else if (std::strcmp(szname, "long-long") == 0) sizeof_long_long = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "float") == 0) + else if (std::strcmp(szname, "float") == 0) sizeof_float = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "double") == 0) + else if (std::strcmp(szname, "double") == 0) sizeof_double = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "long-double") == 0) + else if (std::strcmp(szname, "long-double") == 0) sizeof_long_double = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "pointer") == 0) + else if (std::strcmp(szname, "pointer") == 0) sizeof_pointer = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "size_t") == 0) + else if (std::strcmp(szname, "size_t") == 0) sizeof_size_t = xmlTextAsUInt(sz, error); - else if (std::strcmp(sz->Name(), "wchar_t") == 0) + else if (std::strcmp(szname, "wchar_t") == 0) sizeof_wchar_t = xmlTextAsUInt(sz, error); } } diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 1959aab75187..a13a0115f19c 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -117,19 +117,20 @@ std::string SuppressionList::parseXmlFile(const char *filename) Suppression s; for (const tinyxml2::XMLElement * e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) { + const char *name = e2->Name(); const char *text = empty_if_null(e2->GetText()); - if (std::strcmp(e2->Name(), "id") == 0) + if (std::strcmp(name, "id") == 0) s.errorId = text; - else if (std::strcmp(e2->Name(), "fileName") == 0) + else if (std::strcmp(name, "fileName") == 0) s.fileName = text; - else if (std::strcmp(e2->Name(), "lineNumber") == 0) + else if (std::strcmp(name, "lineNumber") == 0) s.lineNumber = strToInt(text); - else if (std::strcmp(e2->Name(), "symbolName") == 0) + else if (std::strcmp(name, "symbolName") == 0) s.symbolName = text; - else if (*text && std::strcmp(e2->Name(), "hash") == 0) + else if (*text && std::strcmp(name, "hash") == 0) s.hash = strToInt(text); else - return std::string("unknown element '") + e2->Name() + "' in suppressions XML '" + filename + "', expected id/fileName/lineNumber/symbolName/hash."; + return std::string("unknown element '") + name + "' in suppressions XML '" + filename + "', expected id/fileName/lineNumber/symbolName/hash."; } const std::string err = addSuppression(std::move(s));