From 33777c5b720d450dbab5155d43804354724177e6 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Tue, 29 May 2018 13:24:48 +0200 Subject: [PATCH] Improved const correcntess of local variables. --- lib/checkclass.cpp | 4 ++-- lib/checkio.cpp | 2 +- lib/checkleakautovar.cpp | 2 +- lib/checkother.cpp | 2 +- lib/checkstring.cpp | 2 +- lib/cppcheck.cpp | 2 +- lib/errorlogger.cpp | 4 ++-- lib/mathlib.cpp | 2 +- lib/suppressions.cpp | 2 +- lib/symboldatabase.cpp | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2150d234c..06d26b0b6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -434,7 +434,7 @@ static std::string noMemberErrorMessage(const Scope *scope, const char function[ { const std::string &classname = scope ? scope->className : "class"; const std::string type = (scope && scope->type == Scope::eStruct) ? "Struct" : "Class"; - bool isDestructor = (function[0] == 'd'); + const bool isDestructor = (function[0] == 'd'); std::string errmsg = "$symbol:" + classname + '\n'; if (isdefault) { @@ -1300,7 +1300,7 @@ void CheckClass::operatorEq() returnSelfRef = true; } else { // We might have "Self&"" - Token *tok = func->retDef->next(); + const Token * const tok = func->retDef->next(); if (tok && tok->str() == "<" && tok->link() && tok->link()->next() && tok->link()->next()->str() == "&") returnSelfRef = true; } diff --git a/lib/checkio.cpp b/lib/checkio.cpp index b6c87474b..a47fd6145 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -202,7 +202,7 @@ void CheckIO::checkFileUsage() if (fileTok->str() == "stdin") fflushOnInputStreamError(tok, fileTok->str()); else { - Filepointer& f = filepointers[fileTok->varId()]; + const Filepointer& f = filepointers[fileTok->varId()]; if (f.mode == READ_MODE) fflushOnInputStreamError(tok, fileTok->str()); } diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 5ee634fea..3076539ca 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -602,7 +602,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, tok = typeEndTok->linkAt(2); - unsigned varid = typeEndTok->next()->varId(); + const unsigned varid = typeEndTok->next()->varId(); if (isPointerReleased(typeEndTok->tokAt(2), endToken, varid)) continue; diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 635ce5b90..83feb390e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1441,7 +1441,7 @@ void CheckOther::checkPassByReference() if (inconclusive && !_settings->inconclusive) continue; - bool isConst = var->isConst(); + const bool isConst = var->isConst(); if (isConst) { passedByValueError(tok, var->name(), inconclusive); continue; diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index e02e1763d..8e76ed114 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -187,7 +187,7 @@ void CheckString::checkSuspiciousStringCompare() // Pointer addition? if (varTok->str() == "+" && _tokenizer->isC()) { - const Token *tokens[2] = { varTok->astOperand1(), varTok->astOperand2() }; + const Token * const tokens[2] = { varTok->astOperand1(), varTok->astOperand2() }; for (int nr = 0; nr < 2; nr++) { const Token *t = tokens[nr]; while (t && (t->str() == "." || t->str() == "::")) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 653caa2d6..556ec498c 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -857,7 +857,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map(iss.get()); + const char c = static_cast(iss.get()); temp.append(1, c); } @@ -620,7 +620,7 @@ std::string ErrorLogger::toxml(const std::string &str) { std::ostringstream xml; for (std::size_t i = 0U; i < str.length(); i++) { - unsigned char c = str[i]; + const unsigned char c = str[i]; switch (c) { case '<': xml << "<"; diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index b799a350a..7931cbace 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -1048,7 +1048,7 @@ std::string MathLib::getSuffix(const std::string& value) bool isUnsigned = false; unsigned int longState = 0; for (std::size_t i = 1U; i < value.size(); ++i) { - char c = value[value.size() - i]; + const char c = value[value.size() - i]; if (c == 'u' || c == 'U') isUnsigned = true; else if (c == 'L' || c == 'l') diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 539df8557..4c5da51a2 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -77,7 +77,7 @@ std::string Suppressions::parseFile(std::istream &istr) std::string Suppressions::parseXmlFile(const char *filename) { tinyxml2::XMLDocument doc; - tinyxml2::XMLError error = doc.LoadFile(filename); + const tinyxml2::XMLError error = doc.LoadFile(filename); if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) return "File not found"; if (error != tinyxml2::XML_SUCCESS) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 0f8db67e8..5cc18a65a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -910,7 +910,7 @@ void SymbolDatabase::createSymbolDatabaseVariableSymbolTable() // add all variables for (std::list::iterator var = scope->varlist.begin(); var != scope->varlist.end(); ++var) { - unsigned int varId = var->declarationId(); + const unsigned int varId = var->declarationId(); if (varId) _variableList[varId] = &(*var); // fix up variables without type