From 07b5afcdc6293447a7df23646b4acbc86c8769b3 Mon Sep 17 00:00:00 2001 From: jrp2014 Date: Wed, 4 Apr 2018 21:02:13 +0200 Subject: [PATCH] Improve constness --- cli/cmdlineparser.cpp | 10 +++++----- cli/cppcheckexecutor.cpp | 2 +- cli/filelister.cpp | 6 +++--- cli/threadexecutor.cpp | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index cc1c136b3..3cbd6cffb 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -229,7 +229,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) } else if (std::strncmp(argv[i], "--suppress=", 11) == 0) { - std::string suppression = argv[i]+11; + const std::string suppression = argv[i]+11; const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression)); if (!errmsg.empty()) { PrintMessage(errmsg); @@ -257,7 +257,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) if (argv[i][argv[i][3]=='='?4:17] != 0) { std::string paths = argv[i]+(argv[i][3]=='='?4:17); for (;;) { - std::string::size_type pos = paths.find(';'); + const std::string::size_type pos = paths.find(';'); if (pos == std::string::npos) { _settings->basePaths.push_back(Path::fromNativeSeparators(paths)); break; @@ -291,7 +291,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) // Define the XML file version (and enable XML output) else if (std::strncmp(argv[i], "--xml-version=", 14) == 0) { - std::string numberString(argv[i]+14); + const std::string numberString(argv[i]+14); std::istringstream iss(numberString); if (!(iss >> _settings->xml_version)) { @@ -339,7 +339,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) // --error-exitcode=1 else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) { - std::string temp = argv[i]+17; + const std::string temp = argv[i]+17; std::istringstream iss(temp); if (!(iss >> _settings->exitCode)) { _settings->exitCode = 0; @@ -698,7 +698,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) // Specify platform else if (std::strncmp(argv[i], "--platform=", 11) == 0) { - std::string platform(11+argv[i]); + const std::string platform(11+argv[i]); if (platform == "win32A") _settings->platform(Settings::Win32A); diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 76d1f4c45..949ed8cea 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -161,7 +161,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c #endif if (!pathnames.empty()) { // Execute recursiveAddFiles() to each given file parameter - PathMatch matcher(ignored, caseSensitive); + const PathMatch matcher(ignored, caseSensitive); for (std::vector::const_iterator iter = pathnames.begin(); iter != pathnames.end(); ++iter) FileLister::recursiveAddFiles(_files, Path::toNativeSeparators(*iter), _settings->library.markupExtensions(), matcher); } diff --git a/cli/filelister.cpp b/cli/filelister.cpp index ff2112b4a..52a9400c7 100644 --- a/cli/filelister.cpp +++ b/cli/filelister.cpp @@ -64,7 +64,7 @@ static BOOL MyFileExists(const std::string& path) if (fa != INVALID_FILE_ATTRIBUTES && !(fa & FILE_ATTRIBUTE_DIRECTORY)) result = TRUE; #else - BOOL result = PathFileExistsA(path.c_str()); + const BOOL result = PathFileExistsA(path.c_str()); #endif return result; } @@ -89,7 +89,7 @@ void FileLister::addFiles(std::map &files, const std:: const bool checkAllFilesInDir = (MyIsDirectory(cleanedPath) != FALSE); if (checkAllFilesInDir) { - char c = cleanedPath.back(); + const char c = cleanedPath.back(); switch (c) { case '\\': searchPattern += '*'; @@ -104,7 +104,7 @@ void FileLister::addFiles(std::map &files, const std:: basedir = cleanedPath + '\\'; } } else { - std::string::size_type pos = cleanedPath.find_last_of('\\'); + const std::string::size_type pos = cleanedPath.find_last_of('\\'); if (std::string::npos != pos) { basedir = cleanedPath.substr(0, pos + 1); } diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index bc73870a8..1b487492c 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -389,7 +389,7 @@ unsigned int ThreadExecutor::check() } } - DWORD waitResult = WaitForMultipleObjects(_settings.jobs, threadHandles, TRUE, INFINITE); + const DWORD waitResult = WaitForMultipleObjects(_settings.jobs, threadHandles, TRUE, INFINITE); if (waitResult != WAIT_OBJECT_0) { if (waitResult == WAIT_FAILED) { std::cerr << "#### .\nThreadExecutor::check wait failed, result: " << waitResult << " error: " << GetLastError() << std::endl; @@ -454,7 +454,7 @@ unsigned int __stdcall ThreadExecutor::threadProc(void *args) LeaveCriticalSection(&threadExecutor->_fileSync); - std::map::const_iterator fileContent = threadExecutor->_fileContents.find(file); + const std::map::const_iterator fileContent = threadExecutor->_fileContents.find(file); if (fileContent != threadExecutor->_fileContents.end()) { // File content was given as a string result += fileChecker.check(file, fileContent->second); @@ -514,7 +514,7 @@ void ThreadExecutor::report(const ErrorLogger::ErrorMessage &msg, MessageType ms // Alert only about unique errors bool reportError = false; - std::string errmsg = msg.toString(_settings.verbose); + const std::string errmsg = msg.toString(_settings.verbose); EnterCriticalSection(&_errorSync); if (std::find(_errorList.begin(), _errorList.end(), errmsg) == _errorList.end()) {