Improve constness

This commit is contained in:
jrp2014 2018-04-04 21:02:13 +02:00 committed by Daniel Marjamäki
parent 41a46364c8
commit 07b5afcdc6
4 changed files with 12 additions and 12 deletions

View File

@ -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);

View File

@ -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<std::string>::const_iterator iter = pathnames.begin(); iter != pathnames.end(); ++iter)
FileLister::recursiveAddFiles(_files, Path::toNativeSeparators(*iter), _settings->library.markupExtensions(), matcher);
}

View File

@ -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<std::string, std::size_t> &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<std::string, std::size_t> &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);
}

View File

@ -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<std::string, std::string>::const_iterator fileContent = threadExecutor->_fileContents.find(file);
const std::map<std::string, std::string>::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()) {