Skip to content

Commit 07b5afc

Browse files
jrp2014danmar
authored andcommitted
Improve constness
1 parent 41a4636 commit 07b5afc

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
229229
}
230230

231231
else if (std::strncmp(argv[i], "--suppress=", 11) == 0) {
232-
std::string suppression = argv[i]+11;
232+
const std::string suppression = argv[i]+11;
233233
const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression));
234234
if (!errmsg.empty()) {
235235
PrintMessage(errmsg);
@@ -257,7 +257,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
257257
if (argv[i][argv[i][3]=='='?4:17] != 0) {
258258
std::string paths = argv[i]+(argv[i][3]=='='?4:17);
259259
for (;;) {
260-
std::string::size_type pos = paths.find(';');
260+
const std::string::size_type pos = paths.find(';');
261261
if (pos == std::string::npos) {
262262
_settings->basePaths.push_back(Path::fromNativeSeparators(paths));
263263
break;
@@ -291,7 +291,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
291291

292292
// Define the XML file version (and enable XML output)
293293
else if (std::strncmp(argv[i], "--xml-version=", 14) == 0) {
294-
std::string numberString(argv[i]+14);
294+
const std::string numberString(argv[i]+14);
295295

296296
std::istringstream iss(numberString);
297297
if (!(iss >> _settings->xml_version)) {
@@ -339,7 +339,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
339339

340340
// --error-exitcode=1
341341
else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) {
342-
std::string temp = argv[i]+17;
342+
const std::string temp = argv[i]+17;
343343
std::istringstream iss(temp);
344344
if (!(iss >> _settings->exitCode)) {
345345
_settings->exitCode = 0;
@@ -698,7 +698,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
698698

699699
// Specify platform
700700
else if (std::strncmp(argv[i], "--platform=", 11) == 0) {
701-
std::string platform(11+argv[i]);
701+
const std::string platform(11+argv[i]);
702702

703703
if (platform == "win32A")
704704
_settings->platform(Settings::Win32A);

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
161161
#endif
162162
if (!pathnames.empty()) {
163163
// Execute recursiveAddFiles() to each given file parameter
164-
PathMatch matcher(ignored, caseSensitive);
164+
const PathMatch matcher(ignored, caseSensitive);
165165
for (std::vector<std::string>::const_iterator iter = pathnames.begin(); iter != pathnames.end(); ++iter)
166166
FileLister::recursiveAddFiles(_files, Path::toNativeSeparators(*iter), _settings->library.markupExtensions(), matcher);
167167
}

cli/filelister.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static BOOL MyFileExists(const std::string& path)
6464
if (fa != INVALID_FILE_ATTRIBUTES && !(fa & FILE_ATTRIBUTE_DIRECTORY))
6565
result = TRUE;
6666
#else
67-
BOOL result = PathFileExistsA(path.c_str());
67+
const BOOL result = PathFileExistsA(path.c_str());
6868
#endif
6969
return result;
7070
}
@@ -89,7 +89,7 @@ void FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::
8989
const bool checkAllFilesInDir = (MyIsDirectory(cleanedPath) != FALSE);
9090

9191
if (checkAllFilesInDir) {
92-
char c = cleanedPath.back();
92+
const char c = cleanedPath.back();
9393
switch (c) {
9494
case '\\':
9595
searchPattern += '*';
@@ -104,7 +104,7 @@ void FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::
104104
basedir = cleanedPath + '\\';
105105
}
106106
} else {
107-
std::string::size_type pos = cleanedPath.find_last_of('\\');
107+
const std::string::size_type pos = cleanedPath.find_last_of('\\');
108108
if (std::string::npos != pos) {
109109
basedir = cleanedPath.substr(0, pos + 1);
110110
}

cli/threadexecutor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ unsigned int ThreadExecutor::check()
389389
}
390390
}
391391

392-
DWORD waitResult = WaitForMultipleObjects(_settings.jobs, threadHandles, TRUE, INFINITE);
392+
const DWORD waitResult = WaitForMultipleObjects(_settings.jobs, threadHandles, TRUE, INFINITE);
393393
if (waitResult != WAIT_OBJECT_0) {
394394
if (waitResult == WAIT_FAILED) {
395395
std::cerr << "#### .\nThreadExecutor::check wait failed, result: " << waitResult << " error: " << GetLastError() << std::endl;
@@ -454,7 +454,7 @@ unsigned int __stdcall ThreadExecutor::threadProc(void *args)
454454

455455
LeaveCriticalSection(&threadExecutor->_fileSync);
456456

457-
std::map<std::string, std::string>::const_iterator fileContent = threadExecutor->_fileContents.find(file);
457+
const std::map<std::string, std::string>::const_iterator fileContent = threadExecutor->_fileContents.find(file);
458458
if (fileContent != threadExecutor->_fileContents.end()) {
459459
// File content was given as a string
460460
result += fileChecker.check(file, fileContent->second);
@@ -514,7 +514,7 @@ void ThreadExecutor::report(const ErrorLogger::ErrorMessage &msg, MessageType ms
514514

515515
// Alert only about unique errors
516516
bool reportError = false;
517-
std::string errmsg = msg.toString(_settings.verbose);
517+
const std::string errmsg = msg.toString(_settings.verbose);
518518

519519
EnterCriticalSection(&_errorSync);
520520
if (std::find(_errorList.begin(), _errorList.end(), errmsg) == _errorList.end()) {

0 commit comments

Comments
 (0)