Improved const correcntess of local variables.

This commit is contained in:
orbitcowboy 2018-05-29 13:24:48 +02:00
parent b94e5ab9cb
commit 33777c5b72
10 changed files with 12 additions and 12 deletions

View File

@ -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 &classname = scope ? scope->className : "class";
const std::string type = (scope && scope->type == Scope::eStruct) ? "Struct" : "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'; std::string errmsg = "$symbol:" + classname + '\n';
if (isdefault) { if (isdefault) {
@ -1300,7 +1300,7 @@ void CheckClass::operatorEq()
returnSelfRef = true; returnSelfRef = true;
} else { } else {
// We might have "Self<template_parameters>&"" // We might have "Self<template_parameters>&""
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() == "&") if (tok && tok->str() == "<" && tok->link() && tok->link()->next() && tok->link()->next()->str() == "&")
returnSelfRef = true; returnSelfRef = true;
} }

View File

@ -202,7 +202,7 @@ void CheckIO::checkFileUsage()
if (fileTok->str() == "stdin") if (fileTok->str() == "stdin")
fflushOnInputStreamError(tok, fileTok->str()); fflushOnInputStreamError(tok, fileTok->str());
else { else {
Filepointer& f = filepointers[fileTok->varId()]; const Filepointer& f = filepointers[fileTok->varId()];
if (f.mode == READ_MODE) if (f.mode == READ_MODE)
fflushOnInputStreamError(tok, fileTok->str()); fflushOnInputStreamError(tok, fileTok->str());
} }

View File

@ -602,7 +602,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
tok = typeEndTok->linkAt(2); tok = typeEndTok->linkAt(2);
unsigned varid = typeEndTok->next()->varId(); const unsigned varid = typeEndTok->next()->varId();
if (isPointerReleased(typeEndTok->tokAt(2), endToken, varid)) if (isPointerReleased(typeEndTok->tokAt(2), endToken, varid))
continue; continue;

View File

@ -1441,7 +1441,7 @@ void CheckOther::checkPassByReference()
if (inconclusive && !_settings->inconclusive) if (inconclusive && !_settings->inconclusive)
continue; continue;
bool isConst = var->isConst(); const bool isConst = var->isConst();
if (isConst) { if (isConst) {
passedByValueError(tok, var->name(), inconclusive); passedByValueError(tok, var->name(), inconclusive);
continue; continue;

View File

@ -187,7 +187,7 @@ void CheckString::checkSuspiciousStringCompare()
// Pointer addition? // Pointer addition?
if (varTok->str() == "+" && _tokenizer->isC()) { 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++) { for (int nr = 0; nr < 2; nr++) {
const Token *t = tokens[nr]; const Token *t = tokens[nr];
while (t && (t->str() == "." || t->str() == "::")) while (t && (t->str() == "." || t->str() == "::"))

View File

@ -857,7 +857,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<s
//const std::string sourcefile = filesTxtLine.substr(lastColon+1); //const std::string sourcefile = filesTxtLine.substr(lastColon+1);
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
tinyxml2::XMLError error = doc.LoadFile(xmlfile.c_str()); const tinyxml2::XMLError error = doc.LoadFile(xmlfile.c_str());
if (error != tinyxml2::XML_SUCCESS) if (error != tinyxml2::XML_SUCCESS)
continue; continue;

View File

@ -268,7 +268,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
iss.get(); iss.get();
std::string temp; std::string temp;
for (unsigned int i = 0; i < len && iss.good(); ++i) { for (unsigned int i = 0; i < len && iss.good(); ++i) {
char c = static_cast<char>(iss.get()); const char c = static_cast<char>(iss.get());
temp.append(1, c); temp.append(1, c);
} }
@ -620,7 +620,7 @@ std::string ErrorLogger::toxml(const std::string &str)
{ {
std::ostringstream xml; std::ostringstream xml;
for (std::size_t i = 0U; i < str.length(); i++) { for (std::size_t i = 0U; i < str.length(); i++) {
unsigned char c = str[i]; const unsigned char c = str[i];
switch (c) { switch (c) {
case '<': case '<':
xml << "&lt;"; xml << "&lt;";

View File

@ -1048,7 +1048,7 @@ std::string MathLib::getSuffix(const std::string& value)
bool isUnsigned = false; bool isUnsigned = false;
unsigned int longState = 0; unsigned int longState = 0;
for (std::size_t i = 1U; i < value.size(); ++i) { 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') if (c == 'u' || c == 'U')
isUnsigned = true; isUnsigned = true;
else if (c == 'L' || c == 'l') else if (c == 'L' || c == 'l')

View File

@ -77,7 +77,7 @@ std::string Suppressions::parseFile(std::istream &istr)
std::string Suppressions::parseXmlFile(const char *filename) std::string Suppressions::parseXmlFile(const char *filename)
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
tinyxml2::XMLError error = doc.LoadFile(filename); const tinyxml2::XMLError error = doc.LoadFile(filename);
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
return "File not found"; return "File not found";
if (error != tinyxml2::XML_SUCCESS) if (error != tinyxml2::XML_SUCCESS)

View File

@ -910,7 +910,7 @@ void SymbolDatabase::createSymbolDatabaseVariableSymbolTable()
// add all variables // add all variables
for (std::list<Variable>::iterator var = scope->varlist.begin(); var != scope->varlist.end(); ++var) { for (std::list<Variable>::iterator var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
unsigned int varId = var->declarationId(); const unsigned int varId = var->declarationId();
if (varId) if (varId)
_variableList[varId] = &(*var); _variableList[varId] = &(*var);
// fix up variables without type // fix up variables without type