diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 65c9d89d7..68c5120d8 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -340,14 +340,14 @@ const Token * astIsVariableComparison(const Token *tok, const std::string &comp, } else if (tok->str() == comp && tok->astOperand2() && match(tok->astOperand2(), rhs)) { ret = tok->astOperand1(); } - } else if (comp == "!=" && rhs == std::string("0")) { + } else if (comp == "!=" && rhs == "0") { if (tok->str() == "!") { ret = tok->astOperand1(); // handle (!(x==0)) as (x!=0) astIsVariableComparison(ret, "==", "0", &ret); } else ret = tok; - } else if (comp == "==" && rhs == std::string("0")) { + } else if (comp == "==" && rhs == "0") { if (tok->str() == "!") { ret = tok->astOperand1(); // handle (!(x!=0)) as (x==0) diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 280ba6d09..424f65e6f 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -1197,7 +1197,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti else if (strcmp(node->Name(), CppcheckXml::ToolsElementName) == 0) { const std::list toolList = readXmlStringList(node, emptyString, CppcheckXml::ToolElementName, nullptr); for (const std::string &toolName : toolList) { - if (toolName == std::string(CppcheckXml::ClangTidy)) + if (toolName == CppcheckXml::ClangTidy) temp.clangTidy = true; } } else if (strcmp(node->Name(), CppcheckXml::CheckHeadersElementName) == 0) diff --git a/lib/library.cpp b/lib/library.cpp index c68d55979..01f2c43ad 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -442,19 +442,19 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) container.itEndPattern = itEndPattern; const char* const opLessAllowed = node->Attribute("opLessAllowed"); if (opLessAllowed) - container.opLessAllowed = std::string(opLessAllowed) == "true"; + container.opLessAllowed = strcmp(opLessAllowed, "true") == 0; const char* const hasInitializerListConstructor = node->Attribute("hasInitializerListConstructor"); if (hasInitializerListConstructor) - container.hasInitializerListConstructor = std::string(hasInitializerListConstructor) == "true"; + container.hasInitializerListConstructor = strcmp(hasInitializerListConstructor, "true") == 0; const char* const view = node->Attribute("view"); if (view) - container.view = std::string(view) == "true"; + container.view = strcmp(view, "true") == 0; for (const tinyxml2::XMLElement *containerNode = node->FirstChildElement(); containerNode; containerNode = containerNode->NextSiblingElement()) { const std::string containerNodeName = containerNode->Name(); if (containerNodeName == "size" || containerNodeName == "access" || containerNodeName == "other") { for (const tinyxml2::XMLElement *functionNode = containerNode->FirstChildElement(); functionNode; functionNode = functionNode->NextSiblingElement()) { - if (std::string(functionNode->Name()) != "function") { + if (strcmp(functionNode->Name(), "function") != 0) { unknown_elements.insert(functionNode->Name()); continue; } @@ -492,7 +492,7 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) } else if (containerNodeName == "access") { const char* const indexArg = containerNode->Attribute("indexOperator"); if (indexArg) - container.arrayLike_indexOp = std::string(indexArg) == "array-like"; + container.arrayLike_indexOp = strcmp(indexArg, "array-like") == 0; } } else if (containerNodeName == "type") { const char* const templateArg = containerNode->Attribute("templateParameter"); @@ -501,10 +501,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc) const char* const string = containerNode->Attribute("string"); if (string) - container.stdStringLike = std::string(string) == "std-like"; + container.stdStringLike = strcmp(string, "std-like") == 0; const char* const associative = containerNode->Attribute("associative"); if (associative) - container.stdAssociativeLike = std::string(associative) == "std-like"; + container.stdAssociativeLike = strcmp(associative, "std-like") == 0; const char* const unstable = containerNode->Attribute("unstable"); if (unstable) { std::string unstableType = unstable; diff --git a/oss-fuzz/type2.cpp b/oss-fuzz/type2.cpp index f88f4943f..0fe4ce343 100644 --- a/oss-fuzz/type2.cpp +++ b/oss-fuzz/type2.cpp @@ -16,9 +16,11 @@ * along with this program. If not, see . */ -#include #include "type2.h" +#include +#include + static int getValue(const uint8_t *data, size_t dataSize, uint8_t maxValue, bool *done = nullptr) { static size_t pos; // current "data" position @@ -92,9 +94,9 @@ static std::string generateExpression2_Expr(const uint8_t *data, size_t dataSize } case 2: { const char *u = unop[getValue(data,dataSize,sizeof(unop)/sizeof(*unop))]; - if (u == std::string("()")) + if (strcmp(u, "()") == 0) return "(" + generateExpression2_Expr(data, dataSize, numberOfGlobalConstants, depth) + ")"; - else if (u == std::string("++") || u == std::string("--")) + else if (strcmp(u, "++") == 0 || strcmp(u, "--") == 0) return u + generateExpression2_lvalue(data, dataSize); return u + generateExpression2_Expr(data, dataSize, numberOfGlobalConstants, depth); }