Skip to content

Commit fae40c4

Browse files
committed
Change every C version of 'size_t' to C++ 'std::size_t'.
1 parent 639f156 commit fae40c4

27 files changed

+83
-83
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
124124
const bool caseSensitive = true;
125125
#endif
126126
PathMatch matcher(parser.GetIgnoredPaths(), caseSensitive);
127-
for (std::map<std::string, size_t>::iterator i = _files.begin(); i != _files.end();) {
127+
for (std::map<std::string, std::size_t>::iterator i = _files.begin(); i != _files.end();) {
128128
if (matcher.Match(i->first))
129129
_files.erase(i++);
130130
else
@@ -167,14 +167,14 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
167167
if (settings._jobs == 1) {
168168
// Single process
169169

170-
size_t totalfilesize = 0;
171-
for (std::map<std::string, size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
170+
std::size_t totalfilesize = 0;
171+
for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
172172
totalfilesize += i->second;
173173
}
174174

175-
size_t processedsize = 0;
175+
std::size_t processedsize = 0;
176176
unsigned int c = 0;
177-
for (std::map<std::string, size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
177+
for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
178178
returnValue += cppCheck.check(i->first);
179179
processedsize += i->second;
180180
if (!settings._errorsOnly)
@@ -237,7 +237,7 @@ void CppCheckExecutor::reportOut(const std::string &outmsg)
237237
std::cout << outmsg << std::endl;
238238
}
239239

240-
void CppCheckExecutor::reportProgress(const std::string &filename, const char stage[], const size_t value)
240+
void CppCheckExecutor::reportProgress(const std::string &filename, const char stage[], const std::size_t value)
241241
{
242242
(void)filename;
243243

@@ -270,7 +270,7 @@ void CppCheckExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
270270
reportErr(msg);
271271
}
272272

273-
void CppCheckExecutor::reportStatus(size_t fileindex, size_t filecount, size_t sizedone, size_t sizetotal)
273+
void CppCheckExecutor::reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal)
274274
{
275275
if (filecount > 1) {
276276
std::ostringstream oss;

cli/cppcheckexecutor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CppCheckExecutor : public ErrorLogger {
7070
/** xml output of errors */
7171
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
7272

73-
void reportProgress(const std::string &filename, const char stage[], const size_t value);
73+
void reportProgress(const std::string &filename, const char stage[], const std::size_t value);
7474

7575
/**
7676
* Output information messages.
@@ -85,7 +85,7 @@ class CppCheckExecutor : public ErrorLogger {
8585
* @param sizedone The sum of sizes of the files checked.
8686
* @param sizetotal The total sizes of the files.
8787
*/
88-
static void reportStatus(size_t fileindex, size_t filecount, size_t sizedone, size_t sizetotal);
88+
static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal);
8989

9090
protected:
9191

@@ -121,7 +121,7 @@ class CppCheckExecutor : public ErrorLogger {
121121
/**
122122
* Filename associated with size of file
123123
*/
124-
std::map<std::string, size_t> _files;
124+
std::map<std::string, std::size_t> _files;
125125

126126
/**
127127
* Report progress time

cli/filelister.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static BOOL MyFileExists(const std::string& path)
118118

119119
#endif // defined(UNICODE)
120120

121-
void FileLister::recursiveAddFiles(std::map<std::string, size_t> &files, const std::string &path)
121+
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path)
122122
{
123123
// oss is the search string passed into FindFirst and FindNext.
124124
// bdir is the base directory which is used to form pathnames.
@@ -161,7 +161,7 @@ void FileLister::recursiveAddFiles(std::map<std::string, size_t> &files, const s
161161
continue;
162162

163163
#if defined(UNICODE)
164-
size_t length = wcslen(ffd.cFileName);
164+
std::size_t length = wcslen(ffd.cFileName);
165165
char * ansiFfd = new char[length + 1];
166166
TransformUcs2ToAnsi(ffd.cFileName, ansiFfd, length + 1);
167167
#else // defined(UNICODE)
@@ -182,7 +182,7 @@ void FileLister::recursiveAddFiles(std::map<std::string, size_t> &files, const s
182182
const std::string nativename = Path::fromNativeSeparators(fname.str());
183183
// Limitation: file sizes are assumed to fit in a 'size_t'
184184
#ifdef _WIN64
185-
files[nativename] = (static_cast<size_t>(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow;
185+
files[nativename] = (static_cast<std::size_t>(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow;
186186
#else
187187
files[nativename] = ffd.nFileSizeLow;
188188
#endif
@@ -246,7 +246,7 @@ std::string FileLister::getAbsolutePath(const std::string& path)
246246
}
247247

248248
void FileLister::recursiveAddFiles2(std::set<std::string> &seen_paths,
249-
std::map<std::string, size_t> &files,
249+
std::map<std::string, std::size_t> &files,
250250
const std::string &path)
251251
{
252252
std::ostringstream oss;
@@ -279,7 +279,7 @@ void FileLister::recursiveAddFiles2(std::set<std::string> &seen_paths,
279279
struct stat sb;
280280
if (stat(absolute_path.c_str(), &sb) == 0) {
281281
// Limitation: file sizes are assumed to fit in a 'size_t'
282-
files[filename] = static_cast<size_t>(sb.st_size);
282+
files[filename] = static_cast<std::size_t>(sb.st_size);
283283
} else
284284
files[filename] = 0;
285285
}
@@ -294,7 +294,7 @@ void FileLister::recursiveAddFiles2(std::set<std::string> &seen_paths,
294294
}
295295

296296

297-
void FileLister::recursiveAddFiles(std::map<std::string, size_t> &files, const std::string &path)
297+
void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path)
298298
{
299299
std::set<std::string> seen_paths;
300300
recursiveAddFiles2(seen_paths, files, path);

cli/filelister.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FileLister {
3737
* @param files output map that associates the size of each file with its name
3838
* @param path root path
3939
*/
40-
static void recursiveAddFiles(std::map<std::string, size_t> &files, const std::string &path);
40+
static void recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path);
4141

4242
/**
4343
* @brief Is given path a directory?
@@ -55,7 +55,7 @@ class FileLister {
5555
static std::string getAbsolutePath(const std::string& path);
5656

5757
static void recursiveAddFiles2(std::set<std::string> &seen_paths,
58-
std::map<std::string, size_t> &files,
58+
std::map<std::string, std::size_t> &files,
5959
const std::string &path);
6060
#endif
6161
};

cli/pathmatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ bool PathMatch::Match(const std::string &path) const
7474

7575
std::string PathMatch::RemoveFilename(const std::string &path)
7676
{
77-
const size_t ind = path.find_last_of('/');
77+
const std::size_t ind = path.find_last_of('/');
7878
return path.substr(0, ind + 1);
7979
}

cli/threadexecutor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <sstream>
3535
#endif
3636

37-
ThreadExecutor::ThreadExecutor(const std::map<std::string, size_t> &files, Settings &settings, ErrorLogger &errorLogger)
37+
ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger)
3838
: _files(files), _settings(settings), _errorLogger(errorLogger), _fileCount(0)
3939
{
4040
#ifdef THREADING_MODEL_FORK
@@ -125,16 +125,16 @@ unsigned int ThreadExecutor::check()
125125
_fileCount = 0;
126126
unsigned int result = 0;
127127

128-
size_t totalfilesize = 0;
129-
for (std::map<std::string, size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
128+
std::size_t totalfilesize = 0;
129+
for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
130130
totalfilesize += i->second;
131131
}
132132

133133
std::list<int> rpipes;
134134
std::map<pid_t, std::string> childFile;
135135
std::map<int, std::string> pipeFile;
136-
size_t processedsize = 0;
137-
std::map<std::string, size_t>::const_iterator i = _files.begin();
136+
std::size_t processedsize = 0;
137+
std::map<std::string, std::size_t>::const_iterator i = _files.begin();
138138
for (;;) {
139139
// Start a new child
140140
if (i != _files.end() && rpipes.size() < _settings._jobs) {
@@ -207,7 +207,7 @@ unsigned int ThreadExecutor::check()
207207
if (p != pipeFile.end()) {
208208
std::string name = p->second;
209209
pipeFile.erase(p);
210-
std::map<std::string, size_t>::const_iterator fs = _files.find(name);
210+
std::map<std::string, std::size_t>::const_iterator fs = _files.find(name);
211211
if (fs != _files.end()) {
212212
size = fs->second;
213213
}

cli/threadexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Settings;
3939
*/
4040
class ThreadExecutor : public ErrorLogger {
4141
public:
42-
ThreadExecutor(const std::map<std::string, size_t> &files, Settings &settings, ErrorLogger &_errorLogger);
42+
ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &_errorLogger);
4343
virtual ~ThreadExecutor();
4444
unsigned int check();
4545
virtual void reportOut(const std::string &outmsg);
@@ -56,7 +56,7 @@ class ThreadExecutor : public ErrorLogger {
5656
void addFileContent(const std::string &path, const std::string &content);
5757

5858
private:
59-
const std::map<std::string, size_t> &_files;
59+
const std::map<std::string, std::size_t> &_files;
6060
Settings &_settings;
6161
ErrorLogger &_errorLogger;
6262
unsigned int _fileCount;

lib/checkbufferoverrun.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,12 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
972972
// Detect few strcat() calls
973973
const std::string strcatPattern = varid > 0 ? std::string("strcat ( %varid% , %str% ) ;") : ("strcat ( " + varnames + " , %str% ) ;");
974974
if (Token::Match(tok, strcatPattern.c_str(), varid)) {
975-
size_t charactersAppend = 0;
975+
std::size_t charactersAppend = 0;
976976
const Token *tok2 = tok;
977977

978978
while (tok2 && Token::Match(tok2, strcatPattern.c_str(), varid)) {
979979
charactersAppend += Token::getStrLength(tok2->tokAt(4 + varc));
980-
if (charactersAppend >= static_cast<size_t>(total_size)) {
980+
if (charactersAppend >= static_cast<std::size_t>(total_size)) {
981981
bufferOverrunError(tok2);
982982
break;
983983
}
@@ -1882,7 +1882,7 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo(const CheckBufferOverrun::ArrayInfo &ai
18821882
CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const Tokenizer *tokenizer)
18831883
: _varname(var->name()), _varid(var->varId())
18841884
{
1885-
for (size_t i = 0; i < var->dimensions().size(); i++)
1885+
for (std::size_t i = 0; i < var->dimensions().size(); i++)
18861886
_num.push_back(var->dimension(i));
18871887
if (var->typeEndToken()->str() == "*")
18881888
_element_size = tokenizer->sizeOfType(var->typeEndToken());

lib/checkclass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ void CheckClass::initVar(const std::string &varname, const Scope *scope, std::ve
197197

198198
void CheckClass::assignAllVar(std::vector<Usage> &usage) const
199199
{
200-
for (size_t i = 0; i < usage.size(); ++i)
200+
for (std::size_t i = 0; i < usage.size(); ++i)
201201
usage[i].assign = true;
202202
}
203203

204204
void CheckClass::clearAllVar(std::vector<Usage> &usage) const
205205
{
206-
for (size_t i = 0; i < usage.size(); ++i) {
206+
for (std::size_t i = 0; i < usage.size(); ++i) {
207207
usage[i].assign = false;
208208
usage[i].init = false;
209209
}
@@ -212,7 +212,7 @@ void CheckClass::clearAllVar(std::vector<Usage> &usage) const
212212
bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
213213
{
214214
// Iterate through each base class...
215-
for (size_t i = 0; i < scope->derivedFrom.size(); ++i) {
215+
for (std::size_t i = 0; i < scope->derivedFrom.size(); ++i) {
216216
const Scope *derivedFrom = scope->derivedFrom[i].scope;
217217

218218
// Check if base class exists in database
@@ -716,7 +716,7 @@ void CheckClass::noMemset()
716716
void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Scope *type)
717717
{
718718
// recursively check all parent classes
719-
for (size_t i = 0; i < type->derivedFrom.size(); i++) {
719+
for (std::size_t i = 0; i < type->derivedFrom.size(); i++) {
720720
if (type->derivedFrom[i].scope)
721721
checkMemsetType(start, tok, type->derivedFrom[i].scope);
722722
}

lib/checkio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ void CheckIO::checkFileUsage()
9999
std::map<unsigned int, Filepointer> filepointers;
100100

101101
const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
102-
size_t varListSize = symbolDatabase->getVariableListSize();
103-
for (size_t i = 1; i < varListSize; ++i) {
102+
std::size_t varListSize = symbolDatabase->getVariableListSize();
103+
for (std::size_t i = 1; i < varListSize; ++i) {
104104
const Variable* var = symbolDatabase->getVariableFromVarId(i);
105105
if (!var || !var->varId() || !Token::Match(var->typeStartToken(), "FILE *"))
106106
continue;

0 commit comments

Comments
 (0)