From e8c7a723f5c2a2e1fbd84da0b7105d02ab31de49 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 27 Mar 2014 15:50:30 +0100 Subject: [PATCH] Fixed five new true positives in cppcheck, silenced one new false positive (see #5618) --- lib/checkother.cpp | 6 +++--- lib/checkunusedfunctions.cpp | 6 +++--- lib/tokenize.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e8e7e56d6..f6068b213 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1480,7 +1480,7 @@ void CheckOther::invalidFunctionUsage() for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { if (!Token::Match(tok, "%var% ( !!)")) continue; - const std::string functionName = tok->str(); + const std::string& functionName = tok->str(); int argnr = 1; const Token *argtok = tok->tokAt(2); while (argtok && argtok->str() != ")") { @@ -3048,8 +3048,8 @@ void CheckOther::checkComparisonFunctionIsAlwaysTrueOrFalse(void) const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { if (tok->isName() && Token::Match(tok, "isgreater|isless|islessgreater|isgreaterequal|islessequal ( %var% , %var% )")) { - const std::string functionName = tok->str(); // store function name - const std::string varNameLeft = tok->tokAt(2)->str(); // get the left variable name + const std::string& functionName = tok->str(); // store function name + const std::string& varNameLeft = tok->tokAt(2)->str(); // get the left variable name const unsigned int varidLeft = tok->tokAt(2)->varId();// get the left varid const unsigned int varidRight = tok->tokAt(4)->varId();// get the right varid // compare varids: if they are not zero but equal diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 50d9f4843..7362953b2 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -107,14 +107,14 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi while (qPropToken && qPropToken->str() != ")") { if (settings->library.isexportedprefix(tok->str(), qPropToken->str())) { const Token* qNextPropToken = qPropToken->next(); - const std::string value = qNextPropToken->str(); + const std::string& value = qNextPropToken->str(); if (_functions.find(value) != _functions.end()) { _functions[value].usedOtherFile = true; } } if (settings->library.isexportedsuffix(tok->str(), qPropToken->str())) { const Token* qNextPropToken = qPropToken->previous(); - const std::string value = qNextPropToken->str(); + const std::string& value = qNextPropToken->str(); if (value != ")" && _functions.find(value) != _functions.end()) { _functions[value].usedOtherFile = true; } @@ -130,7 +130,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi if (qPropToken->next()) { qPropToken = qPropToken->next(); while (qPropToken && qPropToken->str() != ")") { - const std::string value = qPropToken->str(); + const std::string& value = qPropToken->str(); if (!value.empty()) { _functions[value].usedOtherFile = true; break; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2ce255624..ac20f5eb0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1936,7 +1936,7 @@ void Tokenizer::simplifyArrayAccessSyntax() // 0[a] -> a[0] for (Token *tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, "%num% [ %var% ]")) { - const std::string temp = tok->str(); + std::string temp = tok->str(); tok->str(tok->strAt(2)); tok->tokAt(2)->str(temp); }