fixed and enabled `performance-faster-string-find` clang-tidy warning (#4769)

This commit is contained in:
Oliver Stöneberg 2023-02-08 21:01:51 +01:00 committed by GitHub
parent 14e78e1800
commit 8ef14dad98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 57 additions and 58 deletions

View File

@ -1,5 +1,5 @@
--- ---
Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,google-explicit-constructor,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-misc-non-private-member-variables-in-classes,-clang-analyzer-*,-bugprone-signed-char-misuse,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness,-portability-std-allocator-const,-modernize-deprecated-ios-base-aliases,-bugprone-unchecked-optional-access,-modernize-replace-auto-ptr,-readability-identifier-naming,-portability-simd-intrinsics' Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,google-explicit-constructor,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-redundant-member-init,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-misc-non-private-member-variables-in-classes,-clang-analyzer-*,-bugprone-signed-char-misuse,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness,-portability-std-allocator-const,-modernize-deprecated-ios-base-aliases,-bugprone-unchecked-optional-access,-modernize-replace-auto-ptr,-readability-identifier-naming,-portability-simd-intrinsics'
WarningsAsErrors: '*' WarningsAsErrors: '*'
HeaderFilterRegex: '(cli|gui|lib|oss-fuzz|test|triage)\/[a-z]+\.h' HeaderFilterRegex: '(cli|gui|lib|oss-fuzz|test|triage)\/[a-z]+\.h'
CheckOptions: CheckOptions:

View File

@ -58,7 +58,6 @@ These do not (always) increase readability.
To be documented. To be documented.
`performance-faster-string-find`<br>
`bugprone-narrowing-conversions`<br> `bugprone-narrowing-conversions`<br>
`performance-no-automatic-move`<br> `performance-no-automatic-move`<br>

View File

@ -581,7 +581,7 @@ bool CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string>
for (const std::string &arg : args) { for (const std::string &arg : args) {
if (!joinedArgs.empty()) if (!joinedArgs.empty())
joinedArgs += " "; joinedArgs += " ";
if (arg.find(" ") != std::string::npos) if (arg.find(' ') != std::string::npos)
joinedArgs += '"' + arg + '"'; joinedArgs += '"' + arg + '"';
else else
joinedArgs += arg; joinedArgs += arg;

View File

@ -739,7 +739,7 @@ void ProjectFileDialog::addSingleSuppression(const Suppressions::Suppression &su
bool found_relative = false; bool found_relative = false;
// Replace relative file path in the suppression with the absolute one // Replace relative file path in the suppression with the absolute one
if ((suppression.fileName.find("*") == std::string::npos) && if ((suppression.fileName.find('*') == std::string::npos) &&
(suppression.fileName.find(sep) == std::string::npos)) { (suppression.fileName.find(sep) == std::string::npos)) {
QFileInfo inf(mProjectFile->getFilename()); QFileInfo inf(mProjectFile->getFilename());
QString rootpath = inf.absolutePath(); QString rootpath = inf.absolutePath();

View File

@ -1447,7 +1447,7 @@ void CheckUnusedVar::checkStructMemberUsage()
continue; continue;
// Bail out for template struct, members might be used in non-matching instantiations // Bail out for template struct, members might be used in non-matching instantiations
if (scope.className.find("<") != std::string::npos) if (scope.className.find('<') != std::string::npos)
continue; continue;
// bail out if struct is inherited // bail out if struct is inherited

View File

@ -124,22 +124,22 @@ static std::string unquote(const std::string &s)
static std::vector<std::string> splitString(const std::string &line) static std::vector<std::string> splitString(const std::string &line)
{ {
std::vector<std::string> ret; std::vector<std::string> ret;
std::string::size_type pos1 = line.find_first_not_of(" "); std::string::size_type pos1 = line.find_first_not_of(' ');
while (pos1 < line.size()) { while (pos1 < line.size()) {
std::string::size_type pos2; std::string::size_type pos2;
if (std::strchr("*()", line[pos1])) { if (std::strchr("*()", line[pos1])) {
ret.push_back(line.substr(pos1,1)); ret.push_back(line.substr(pos1,1));
pos1 = line.find_first_not_of(" ", pos1 + 1); pos1 = line.find_first_not_of(' ', pos1 + 1);
continue; continue;
} }
if (line[pos1] == '<') if (line[pos1] == '<')
pos2 = line.find(">", pos1); pos2 = line.find('>', pos1);
else if (line[pos1] == '\"') else if (line[pos1] == '\"')
pos2 = line.find("\"", pos1+1); pos2 = line.find('\"', pos1+1);
else if (line[pos1] == '\'') { else if (line[pos1] == '\'') {
pos2 = line.find("\'", pos1+1); pos2 = line.find('\'', pos1+1);
if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)
pos2 = line.find("\'", pos2 + 3); pos2 = line.find('\'', pos2 + 3);
} else { } else {
pos2 = pos1; pos2 = pos1;
while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum((unsigned char)line[pos2]))) while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum((unsigned char)line[pos2])))
@ -159,10 +159,10 @@ static std::vector<std::string> splitString(const std::string &line)
} }
} }
pos2 = line.find(" ", pos1) - 1; pos2 = line.find(' ', pos1) - 1;
if ((std::isalpha(line[pos1]) || line[pos1] == '_') && if ((std::isalpha(line[pos1]) || line[pos1] == '_') &&
line.find("::", pos1) < pos2 && line.find("::", pos1) < pos2 &&
line.find("::", pos1) < line.find("<", pos1)) { line.find("::", pos1) < line.find('<', pos1)) {
pos2 = line.find("::", pos1); pos2 = line.find("::", pos1);
ret.push_back(line.substr(pos1, pos2-pos1)); ret.push_back(line.substr(pos1, pos2-pos1));
ret.emplace_back("::"); ret.emplace_back("::");
@ -170,10 +170,10 @@ static std::vector<std::string> splitString(const std::string &line)
continue; continue;
} }
if ((std::isalpha(line[pos1]) || line[pos1] == '_') && if ((std::isalpha(line[pos1]) || line[pos1] == '_') &&
line.find("<", pos1) < pos2 && line.find('<', pos1) < pos2 &&
line.find("<<",pos1) != line.find("<",pos1) && line.find("<<",pos1) != line.find('<',pos1) &&
line.find(">", pos1) != std::string::npos && line.find('>', pos1) != std::string::npos &&
line.find(">", pos1) > pos2) { line.find('>', pos1) > pos2) {
int level = 0; int level = 0;
for (pos2 = pos1; pos2 < line.size(); ++pos2) { for (pos2 = pos1; pos2 < line.size(); ++pos2) {
if (line[pos2] == '<') if (line[pos2] == '<')
@ -186,7 +186,7 @@ static std::vector<std::string> splitString(const std::string &line)
} }
if (level > 1 && pos2 + 1 >= line.size()) if (level > 1 && pos2 + 1 >= line.size())
return std::vector<std::string> {}; return std::vector<std::string> {};
pos2 = line.find(" ", pos2); pos2 = line.find(' ', pos2);
if (pos2 != std::string::npos) if (pos2 != std::string::npos)
--pos2; --pos2;
} }
@ -196,7 +196,7 @@ static std::vector<std::string> splitString(const std::string &line)
break; break;
} }
ret.push_back(line.substr(pos1, pos2+1-pos1)); ret.push_back(line.substr(pos1, pos2+1-pos1));
pos1 = line.find_first_not_of(" ", pos2 + 1); pos1 = line.find_first_not_of(' ', pos2 + 1);
} }
return ret; return ret;
} }
@ -546,8 +546,8 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList *tokenList, const s
std::string type; std::string type;
if (str.find(" (") != std::string::npos) { if (str.find(" (") != std::string::npos) {
if (str.find("<") != std::string::npos) if (str.find('<') != std::string::npos)
type = str.substr(1, str.find("<")) + "...>"; type = str.substr(1, str.find('<')) + "...>";
else else
type = str.substr(1,str.find(" (")-1); type = str.substr(1,str.find(" (")-1);
} else } else
@ -557,8 +557,8 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList *tokenList, const s
type.erase(type.find("(*)(")); type.erase(type.find("(*)("));
type += "*"; type += "*";
} }
if (type.find("(") != std::string::npos) if (type.find('(') != std::string::npos)
type.erase(type.find("(")); type.erase(type.find('('));
std::stack<Token *> lpar; std::stack<Token *> lpar;
for (const std::string &s: splitString(type)) { for (const std::string &s: splitString(type)) {
@ -620,7 +620,7 @@ void clangimport::AstNode::setValueType(Token *tok)
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
const std::string &type = getType(i); const std::string &type = getType(i);
if (type.find("<") != std::string::npos) if (type.find('<') != std::string::npos)
// TODO // TODO
continue; continue;
@ -897,8 +897,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
return newtok; return newtok;
} }
std::string type = getType(); std::string type = getType();
if (type.find("*") != std::string::npos) if (type.find('*') != std::string::npos)
type = type.erase(type.rfind("*")); type = type.erase(type.rfind('*'));
addTypeTokens(tokenList, type); addTypeTokens(tokenList, type);
if (!children.empty()) { if (!children.empty()) {
Token *bracket1 = addtoken(tokenList, "["); Token *bracket1 = addtoken(tokenList, "[");
@ -1577,7 +1577,7 @@ void clangimport::parseClangAstDump(Tokenizer *tokenizer, std::istream &f)
std::string line; std::string line;
std::vector<AstNodePtr> tree; std::vector<AstNodePtr> tree;
while (std::getline(f,line)) { while (std::getline(f,line)) {
const std::string::size_type pos1 = line.find("-"); const std::string::size_type pos1 = line.find('-');
if (pos1 == std::string::npos) if (pos1 == std::string::npos)
continue; continue;
if (!tree.empty() && line.substr(pos1) == "-<<<NULL>>>") { if (!tree.empty() && line.substr(pos1) == "-<<<NULL>>>") {
@ -1585,7 +1585,7 @@ void clangimport::parseClangAstDump(Tokenizer *tokenizer, std::istream &f)
tree[level - 1]->children.push_back(nullptr); tree[level - 1]->children.push_back(nullptr);
continue; continue;
} }
const std::string::size_type pos2 = line.find(" ", pos1); const std::string::size_type pos2 = line.find(' ', pos1);
if (pos2 < pos1 + 4 || pos2 == std::string::npos) if (pos2 < pos1 + 4 || pos2 == std::string::npos)
continue; continue;
const std::string nodeType = line.substr(pos1+1, pos2 - pos1 - 1); const std::string nodeType = line.substr(pos1+1, pos2 - pos1 - 1);

View File

@ -162,7 +162,7 @@ namespace {
in >> json; in >> json;
return parseAddonInfo(json, fileName, exename); return parseAddonInfo(json, fileName, exename);
} }
if (fileName.find(".") == std::string::npos) if (fileName.find('.') == std::string::npos)
return getAddonInfo(fileName + ".py", exename); return getAddonInfo(fileName + ".py", exename);
if (endsWith(fileName, ".py")) { if (endsWith(fileName, ".py")) {
@ -170,12 +170,12 @@ namespace {
if (scriptFile.empty()) if (scriptFile.empty())
return "Did not find addon " + fileName; return "Did not find addon " + fileName;
std::string::size_type pos1 = scriptFile.rfind("/"); std::string::size_type pos1 = scriptFile.rfind('/');
if (pos1 == std::string::npos) if (pos1 == std::string::npos)
pos1 = 0; pos1 = 0;
else else
pos1++; pos1++;
std::string::size_type pos2 = scriptFile.rfind("."); std::string::size_type pos2 = scriptFile.rfind('.');
if (pos2 < pos1) if (pos2 < pos1)
pos2 = std::string::npos; pos2 = std::string::npos;
name = scriptFile.substr(pos1, pos2 - pos1); name = scriptFile.substr(pos1, pos2 - pos1);
@ -201,7 +201,7 @@ namespace {
static std::string cmdFileName(std::string f) static std::string cmdFileName(std::string f)
{ {
f = Path::toNativeSeparators(f); f = Path::toNativeSeparators(f);
if (f.find(" ") != std::string::npos) if (f.find(' ') != std::string::npos)
return "\"" + f + "\""; return "\"" + f + "\"";
return f; return f;
} }
@ -215,7 +215,7 @@ static std::vector<std::string> split(const std::string &str, const std::string
break; break;
if (str[startPos] == '\"') { if (str[startPos] == '\"') {
const std::string::size_type endPos = str.find("\"", startPos + 1); const std::string::size_type endPos = str.find('\"', startPos + 1);
ret.push_back(str.substr(startPos + 1, endPos - startPos - 1)); ret.push_back(str.substr(startPos + 1, endPos - startPos - 1));
startPos = (endPos < str.size()) ? (endPos + 1) : endPos; startPos = (endPos < str.size()) ? (endPos + 1) : endPos;
continue; continue;
@ -415,8 +415,8 @@ static bool reportClangErrors(std::istream &is, const std::function<void(const E
continue; continue;
// file:line:column: error: .... // file:line:column: error: ....
const std::string::size_type pos2 = line.rfind(":", pos3 - 1); const std::string::size_type pos2 = line.rfind(':', pos3 - 1);
const std::string::size_type pos1 = line.rfind(":", pos2 - 1); const std::string::size_type pos1 = line.rfind(':', pos2 - 1);
if (pos1 >= pos2 || pos2 >= pos3) if (pos1 >= pos2 || pos2 >= pos3)
continue; continue;
@ -424,7 +424,7 @@ static bool reportClangErrors(std::istream &is, const std::function<void(const E
const std::string filename = line.substr(0, pos1); const std::string filename = line.substr(0, pos1);
const std::string linenr = line.substr(pos1+1, pos2-pos1-1); const std::string linenr = line.substr(pos1+1, pos2-pos1-1);
const std::string colnr = line.substr(pos2+1, pos3-pos2-1); const std::string colnr = line.substr(pos2+1, pos3-pos2-1);
const std::string msg = line.substr(line.find(":", pos3+1) + 2); const std::string msg = line.substr(line.find(':', pos3+1) + 2);
const std::string locFile = Path::toNativeSeparators(filename); const std::string locFile = Path::toNativeSeparators(filename);
ErrorMessage::FileLocation loc; ErrorMessage::FileLocation loc;
@ -1701,8 +1701,8 @@ void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
endColumnPos = line.find(": warning:"); endColumnPos = line.find(": warning:");
} }
const std::size_t endLinePos = line.rfind(":", endColumnPos-1); const std::size_t endLinePos = line.rfind(':', endColumnPos-1);
const std::size_t endNamePos = line.rfind(":", endLinePos - 1); const std::size_t endNamePos = line.rfind(':', endLinePos - 1);
const std::size_t endMsgTypePos = line.find(':', endColumnPos + 2); const std::size_t endMsgTypePos = line.find(':', endColumnPos + 2);
const std::size_t endErrorPos = line.rfind('[', std::string::npos); const std::size_t endErrorPos = line.rfind('[', std::string::npos);
if (endLinePos==std::string::npos || endNamePos==std::string::npos || endMsgTypePos==std::string::npos || endErrorPos==std::string::npos) if (endLinePos==std::string::npos || endNamePos==std::string::npos || endMsgTypePos==std::string::npos || endErrorPos==std::string::npos)

View File

@ -118,8 +118,8 @@ ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenLis
const Token *tok = e.first; const Token *tok = e.first;
std::string info = e.second; std::string info = e.second;
if (info.compare(0,8,"$symbol:") == 0 && info.find("\n") < info.size()) { if (info.compare(0,8,"$symbol:") == 0 && info.find('\n') < info.size()) {
const std::string::size_type pos = info.find("\n"); const std::string::size_type pos = info.find('\n');
const std::string &symbolName = info.substr(8, pos - 8); const std::string &symbolName = info.substr(8, pos - 8);
info = replaceStr(info.substr(pos+1), "$symbol", symbolName); info = replaceStr(info.substr(pos+1), "$symbol", symbolName);
} }
@ -361,7 +361,7 @@ void ErrorMessage::deserialize(const std::string &data)
break; break;
} }
const std::string::size_type start = pos; const std::string::size_type start = pos;
pos = temp.find("\t", pos); pos = temp.find('\t', pos);
if (pos == std::string::npos) { if (pos == std::string::npos) {
substrings.push_back(temp.substr(start)); substrings.push_back(temp.substr(start));
break; break;

View File

@ -264,7 +264,7 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
// TODO: This is a quick bailout to avoid FP #9420, there are false negatives (TODO_ASSERT_EQUALS) // TODO: This is a quick bailout to avoid FP #9420, there are false negatives (TODO_ASSERT_EQUALS)
return Result(Result::Type::BAILOUT); return Result(Result::Type::BAILOUT);
if (expr->isName() && Token::Match(tok, "%name% (") && tok->str().find("<") != std::string::npos && tok->str().find(expr->str()) != std::string::npos) if (expr->isName() && Token::Match(tok, "%name% (") && tok->str().find('<') != std::string::npos && tok->str().find(expr->str()) != std::string::npos)
return Result(Result::Type::BAILOUT); return Result(Result::Type::BAILOUT);
if (exprVarIds.find(tok->varId()) != exprVarIds.end()) { if (exprVarIds.find(tok->varId()) != exprVarIds.end()) {

View File

@ -393,7 +393,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) { for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) {
if (arg.is<std::string>()) { if (arg.is<std::string>()) {
std::string str = arg.get<std::string>(); std::string str = arg.get<std::string>();
if (str.find(" ") != std::string::npos) if (str.find(' ') != std::string::npos)
str = "\"" + str + "\""; str = "\"" + str + "\"";
command += str + " "; command += str + " ";
} }

View File

@ -100,7 +100,7 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std:
return false; return false;
// skip spaces after "cppcheck-suppress" // skip spaces after "cppcheck-suppress"
const std::string::size_type pos2 = comment.find_first_not_of(" ", pos1+cppchecksuppress.size()); const std::string::size_type pos2 = comment.find_first_not_of(' ', pos1+cppchecksuppress.size());
if (pos2 == std::string::npos) if (pos2 == std::string::npos)
return false; return false;

View File

@ -106,7 +106,7 @@ static std::vector<std::string> getSummaryFiles(const std::string &filename)
std::string line; std::string line;
while (std::getline(fin, line)) { while (std::getline(fin, line)) {
const std::string::size_type dotA = line.find(".a"); const std::string::size_type dotA = line.find(".a");
const std::string::size_type colon = line.find(":"); const std::string::size_type colon = line.find(':');
if (colon > line.size() || dotA > colon) if (colon > line.size() || dotA > colon)
continue; continue;
std::string f = line.substr(0,colon); std::string f = line.substr(0,colon);
@ -122,7 +122,7 @@ static std::vector<std::string> getSummaryData(const std::string &line, const st
const std::string::size_type start = line.find(" " + data + ":["); const std::string::size_type start = line.find(" " + data + ":[");
if (start == std::string::npos) if (start == std::string::npos)
return ret; return ret;
const std::string::size_type end = line.find("]", start); const std::string::size_type end = line.find(']', start);
if (end >= line.size()) if (end >= line.size())
return ret; return ret;
@ -172,7 +172,7 @@ void Summaries::loadReturn(const std::string &buildDir, std::set<std::string> &s
while (std::getline(fin, line)) { while (std::getline(fin, line)) {
// Get function name // Get function name
const std::string::size_type pos1 = 0; const std::string::size_type pos1 = 0;
const std::string::size_type pos2 = line.find(" ", pos1); const std::string::size_type pos2 = line.find(' ', pos1);
const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2); const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2);
std::vector<std::string> call = getSummaryData(line, "call"); std::vector<std::string> call = getSummaryData(line, "call");
functionCalls[functionName] = call; functionCalls[functionName] = call;

View File

@ -123,8 +123,8 @@ std::vector<Suppressions::Suppression> Suppressions::parseMultiSuppressComment(c
std::vector<Suppression> suppressions; std::vector<Suppression> suppressions;
// If this function is called we assume that comment starts with "cppcheck-suppress[". // If this function is called we assume that comment starts with "cppcheck-suppress[".
const std::string::size_type start_position = comment.find("["); const std::string::size_type start_position = comment.find('[');
const std::string::size_type end_position = comment.find("]", start_position); const std::string::size_type end_position = comment.find(']', start_position);
if (end_position == std::string::npos) { if (end_position == std::string::npos) {
if (errorMessage && errorMessage->empty()) if (errorMessage && errorMessage->empty())
*errorMessage = "Bad multi suppression '" + comment + "'. legal format is cppcheck-suppress[errorId, errorId symbolName=arr, ...]"; *errorMessage = "Bad multi suppression '" + comment + "'. legal format is cppcheck-suppress[errorId, errorId symbolName=arr, ...]";
@ -134,7 +134,7 @@ std::vector<Suppressions::Suppression> Suppressions::parseMultiSuppressComment(c
// parse all suppressions // parse all suppressions
for (std::string::size_type pos = start_position; pos < end_position;) { for (std::string::size_type pos = start_position; pos < end_position;) {
const std::string::size_type pos1 = pos + 1; const std::string::size_type pos1 = pos + 1;
pos = comment.find(",", pos1); pos = comment.find(',', pos1);
const std::string::size_type pos2 = (pos < end_position) ? pos : end_position; const std::string::size_type pos2 = (pos < end_position) ? pos : end_position;
if (pos1 == pos2) if (pos1 == pos2)
continue; continue;
@ -179,7 +179,7 @@ std::string Suppressions::addSuppressionLine(const std::string &line)
Suppressions::Suppression suppression; Suppressions::Suppression suppression;
// Strip any end of line comments // Strip any end of line comments
std::string::size_type endpos = std::min(line.find("#"), line.find("//")); std::string::size_type endpos = std::min(line.find('#'), line.find("//"));
if (endpos != std::string::npos) { if (endpos != std::string::npos) {
while (endpos > 0 && std::isspace(line[endpos-1])) { while (endpos > 0 && std::isspace(line[endpos-1])) {
endpos--; endpos--;

View File

@ -2051,12 +2051,12 @@ Variable::Variable(const Token *name_, const std::string &clangType, const Token
setFlag(fIsRValueRef, true); setFlag(fIsRValueRef, true);
} }
std::string::size_type pos = clangType.find("["); std::string::size_type pos = clangType.find('[');
if (pos != std::string::npos) { if (pos != std::string::npos) {
setFlag(fIsArray, true); setFlag(fIsArray, true);
do { do {
const std::string::size_type pos1 = pos+1; const std::string::size_type pos1 = pos+1;
pos = clangType.find("]", pos1); pos = clangType.find(']', pos1);
Dimension dim; Dimension dim;
dim.tok = nullptr; dim.tok = nullptr;
dim.known = pos > pos1; dim.known = pos > pos1;
@ -6613,7 +6613,7 @@ static const Token* parsedecl(const Token* type,
parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings, isCpp); parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings, isCpp);
else if (Token::Match(type, "const|constexpr")) else if (Token::Match(type, "const|constexpr"))
valuetype->constness |= (1 << (valuetype->pointer - pointer0)); valuetype->constness |= (1 << (valuetype->pointer - pointer0));
else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find("<")) { else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find('<')) {
TokenList typeTokens(settings); TokenList typeTokens(settings);
std::string::size_type pos1 = 0; std::string::size_type pos1 = 0;
do { do {

View File

@ -1514,7 +1514,7 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c
std::string::size_type end = 0; std::string::size_type end = 0;
bool inTemplate = false; bool inTemplate = false;
int level = 0; int level = 0;
while ((end = templateDeclaration.scope().find(" ", start)) != std::string::npos) { while ((end = templateDeclaration.scope().find(' ', start)) != std::string::npos) {
std::string token = templateDeclaration.scope().substr(start, end - start); std::string token = templateDeclaration.scope().substr(start, end - start);
// done if scopes overlap // done if scopes overlap
if (token == tokStart->str() && tok->strAt(-1) != "::") if (token == tokStart->str() && tok->strAt(-1) != "::")

View File

@ -1445,7 +1445,7 @@ void Tokenizer::simplifyTypedef()
if (it->recordTypes.find(start->str()) != it->recordTypes.end()) { if (it->recordTypes.find(start->str()) != it->recordTypes.end()) {
std::string::size_type spaceIdx = 0; std::string::size_type spaceIdx = 0;
std::string::size_type startIdx = 0; std::string::size_type startIdx = 0;
while ((spaceIdx = removed1.find(" ", startIdx)) != std::string::npos) { while ((spaceIdx = removed1.find(' ', startIdx)) != std::string::npos) {
tok2->previous()->insertToken(removed1.substr(startIdx, spaceIdx - startIdx)); tok2->previous()->insertToken(removed1.substr(startIdx, spaceIdx - startIdx));
startIdx = spaceIdx + 1; startIdx = spaceIdx + 1;
} }
@ -2548,7 +2548,7 @@ bool Tokenizer::simplifyUsing()
tok1->deletePrevious(); tok1->deletePrevious();
break; break;
} else { } else {
const std::string::size_type idx = fullScope.rfind(" "); const std::string::size_type idx = fullScope.rfind(' ');
if (idx == std::string::npos) if (idx == std::string::npos)
break; break;
@ -2695,7 +2695,7 @@ bool Tokenizer::simplifyUsing()
if (tempScope->recordTypes.find(start->str()) != tempScope->recordTypes.end()) { if (tempScope->recordTypes.find(start->str()) != tempScope->recordTypes.end()) {
std::string::size_type spaceIdx = 0; std::string::size_type spaceIdx = 0;
std::string::size_type startIdx = 0; std::string::size_type startIdx = 0;
while ((spaceIdx = removed1.find(" ", startIdx)) != std::string::npos) { while ((spaceIdx = removed1.find(' ', startIdx)) != std::string::npos) {
tok1->previous()->insertToken(removed1.substr(startIdx, spaceIdx - startIdx)); tok1->previous()->insertToken(removed1.substr(startIdx, spaceIdx - startIdx));
startIdx = spaceIdx + 1; startIdx = spaceIdx + 1;
} }