Skip to content

Commit 667e4f4

Browse files
committed
fixed some -Wsign-compare compiler warnings [skip ci]
1 parent 9d674c2 commit 667e4f4

23 files changed

+76
-76
lines changed

lib/analyzerinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ std::string AnalyzerInformation::skipAnalysis(const tinyxml2::XMLDocument &analy
124124
return "";
125125
}
126126

127-
std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fsFileId)
127+
std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId)
128128
{
129129
std::string line;
130130
while (std::getline(filesTxt,line)) {

lib/analyzerinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CPPCHECKLIB AnalyzerInformation {
8787
protected:
8888
static std::string getFilesTxt(const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings);
8989

90-
static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fsFileId);
90+
static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId);
9191

9292
static std::string skipAnalysis(const tinyxml2::XMLDocument &analyzerInfoDoc, std::size_t hash, std::list<ErrorMessage> &errors);
9393

lib/check64bit.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ void Check64BitPortability::pointerassignment()
9595
if (!returnType)
9696
continue;
9797

98-
if (retPointer && !returnType->typeScope && returnType->pointer == 0U)
98+
if (retPointer && !returnType->typeScope && returnType->pointer == 0)
9999
returnIntegerError(tok);
100100

101101
if (!retPointer) {
102-
bool warn = returnType->pointer >= 1U;
102+
bool warn = returnType->pointer >= 1;
103103
if (!warn) {
104104
const Token* tok2 = tok->astOperand1();
105105
while (tok2 && tok2->isCast())
@@ -124,17 +124,17 @@ void Check64BitPortability::pointerassignment()
124124
continue;
125125

126126
// Assign integer to pointer..
127-
if (lhstype->pointer >= 1U &&
127+
if (lhstype->pointer >= 1 &&
128128
!tok->astOperand2()->isNumber() &&
129-
rhstype->pointer == 0U &&
129+
rhstype->pointer == 0 &&
130130
rhstype->originalTypeName.empty() &&
131131
rhstype->type == ValueType::Type::INT &&
132132
!isFunctionPointer(tok->astOperand1()))
133133
assignmentIntegerToAddressError(tok);
134134

135135
// Assign pointer to integer..
136-
if (rhstype->pointer >= 1U &&
137-
lhstype->pointer == 0U &&
136+
if (rhstype->pointer >= 1 &&
137+
lhstype->pointer == 0 &&
138138
lhstype->originalTypeName.empty() &&
139139
lhstype->isIntegral() &&
140140
lhstype->type >= ValueType::Type::CHAR &&

lib/checkbufferoverrun.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ void CheckBufferOverrun::bufferOverflow()
652652
if (!mSettings->library.hasminsize(tok))
653653
continue;
654654
const std::vector<const Token *> args = getArguments(tok);
655-
for (int argnr = 0; argnr < args.size(); ++argnr) {
655+
for (size_t argnr = 0; argnr < args.size(); ++argnr) {
656656
if (!args[argnr]->valueType() || args[argnr]->valueType()->pointer == 0)
657657
continue;
658658
const std::vector<Library::ArgumentChecks::MinSize> *minsizes = mSettings->library.argminsizes(tok, argnr + 1);
@@ -844,7 +844,7 @@ void CheckBufferOverrun::argumentSize()
844844
// If argument is '%type% a[num]' then check bounds against num
845845
const Function *callfunc = tok->function();
846846
const std::vector<const Token *> callargs = getArguments(tok);
847-
for (nonneg int paramIndex = 0; paramIndex < callargs.size() && paramIndex < callfunc->argCount(); ++paramIndex) {
847+
for (size_t paramIndex = 0; paramIndex < callargs.size() && paramIndex < callfunc->argCount(); ++paramIndex) {
848848
const Variable* const argument = callfunc->getArgumentVar(paramIndex);
849849
if (!argument || !argument->nameToken() || !argument->isArray())
850850
continue;

lib/checkclass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok)
23582358
for (const Function &func : scope->functionList) {
23592359
if (func.name() == tok->str()) {
23602360
const Token* tok2 = tok->tokAt(2);
2361-
int argsPassed = tok2->str() == ")" ? 0 : 1;
2361+
size_t argsPassed = tok2->str() == ")" ? 0 : 1;
23622362
for (;;) {
23632363
tok2 = tok2->nextArgument();
23642364
if (tok2)
@@ -2455,9 +2455,9 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
24552455

24562456
if (const Function* f = funcTok->function()) { // check known function
24572457
const std::vector<const Token*> args = getArguments(funcTok);
2458-
const auto argMax = std::min<nonneg int>(args.size(), f->argCount());
2458+
const auto argMax = std::min<size_t>(args.size(), f->argCount());
24592459

2460-
for (nonneg int argIndex = 0; argIndex < argMax; ++argIndex) {
2460+
for (size_t argIndex = 0; argIndex < argMax; ++argIndex) {
24612461
const Variable* const argVar = f->getArgumentVar(argIndex);
24622462
if (!argVar || ((argVar->isArrayOrPointer() || argVar->isReference()) &&
24632463
!(argVar->valueType() && argVar->valueType()->isConst(argVar->valueType()->pointer)))) { // argument might be modified

lib/checkfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void CheckFunctions::invalidFunctionUsage()
116116
continue;
117117
const Token * const functionToken = tok;
118118
const std::vector<const Token *> arguments = getArguments(tok);
119-
for (int argnr = 1; argnr <= arguments.size(); ++argnr) {
119+
for (size_t argnr = 1; argnr <= arguments.size(); ++argnr) {
120120
const Token * const argtok = arguments[argnr-1];
121121

122122
// check <valid>...</valid>

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
396396
});
397397
});
398398
if (hasOutParam) {
399-
for (int i = 0; i < args.size(); i++) {
399+
for (size_t i = 0; i < args.size(); i++) {
400400
if (!argChecks.count(i + 1))
401401
continue;
402402
const ArgumentChecks argCheck = argChecks.at(i + 1);

lib/checknullpointer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace {
5454

5555
//---------------------------------------------------------------------------
5656

57-
static bool checkNullpointerFunctionCallPlausibility(const Function* func, unsigned int arg)
57+
static bool checkNullpointerFunctionCallPlausibility(const Function* func, size_t arg)
5858
{
5959
return !func || (func->argCount() >= arg && func->getArgumentVar(arg - 1) && func->getArgumentVar(arg - 1)->isPointer());
6060
}
@@ -73,7 +73,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
7373

7474
const std::vector<const Token *> args = getArguments(&tok);
7575

76-
for (int argnr = 1; argnr <= args.size(); ++argnr) {
76+
for (size_t argnr = 1; argnr <= args.size(); ++argnr) {
7777
const Token *param = args[argnr - 1];
7878
if ((!checkNullArg || library.isnullargbad(&tok, argnr)) && checkNullpointerFunctionCallPlausibility(tok.function(), argnr))
7979
var.push_back(param);
@@ -390,7 +390,7 @@ void CheckNullPointer::nullConstantDereference()
390390

391391
else if (Token::Match(tok->previous(), "::|. %name% (")) {
392392
const std::vector<const Token *> &args = getArguments(tok);
393-
for (int argnr = 0; argnr < args.size(); ++argnr) {
393+
for (size_t argnr = 0; argnr < args.size(); ++argnr) {
394394
const Token *argtok = args[argnr];
395395
if (!argtok->hasKnownIntValue())
396396
continue;

lib/checkother.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,7 +3291,7 @@ static bool constructorTakesReference(const Scope * const classScope)
32913291
{
32923292
return std::any_of(classScope->functionList.begin(), classScope->functionList.end(), [&](const Function& constructor) {
32933293
if (constructor.isConstructor()) {
3294-
for (int argnr = 0U; argnr < constructor.argCount(); argnr++) {
3294+
for (size_t argnr = 0U; argnr < constructor.argCount(); argnr++) {
32953295
const Variable * const argVar = constructor.getArgumentVar(argnr);
32963296
if (argVar && argVar->isReference()) {
32973297
return true;
@@ -4014,7 +4014,7 @@ void CheckOther::checkFuncArgNamesDifferent()
40144014
std::vector<const Token *> declarations(function->argCount());
40154015
std::vector<const Token *> definitions(function->argCount());
40164016
const Token * decl = function->argDef->next();
4017-
for (int j = 0; j < function->argCount(); ++j) {
4017+
for (size_t j = 0; j < function->argCount(); ++j) {
40184018
declarations[j] = nullptr;
40194019
definitions[j] = nullptr;
40204020
// get the definition
@@ -4044,11 +4044,11 @@ void CheckOther::checkFuncArgNamesDifferent()
40444044
// check for different argument order
40454045
if (warning) {
40464046
bool order_different = false;
4047-
for (int j = 0; j < function->argCount(); ++j) {
4047+
for (size_t j = 0; j < function->argCount(); ++j) {
40484048
if (!declarations[j] || !definitions[j] || declarations[j]->str() == definitions[j]->str())
40494049
continue;
40504050

4051-
for (int k = 0; k < function->argCount(); ++k) {
4051+
for (size_t k = 0; k < function->argCount(); ++k) {
40524052
if (j != k && definitions[k] && declarations[j]->str() == definitions[k]->str()) {
40534053
order_different = true;
40544054
break;
@@ -4062,15 +4062,15 @@ void CheckOther::checkFuncArgNamesDifferent()
40624062
}
40634063
// check for different argument names
40644064
if (style && inconclusive) {
4065-
for (int j = 0; j < function->argCount(); ++j) {
4065+
for (size_t j = 0; j < function->argCount(); ++j) {
40664066
if (declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str())
40674067
funcArgNamesDifferent(function->name(), j, declarations[j], definitions[j]);
40684068
}
40694069
}
40704070
}
40714071
}
40724072

4073-
void CheckOther::funcArgNamesDifferent(const std::string & functionName, nonneg int index,
4073+
void CheckOther::funcArgNamesDifferent(const std::string & functionName, size_t index,
40744074
const Token* declaration, const Token* definition)
40754075
{
40764076
std::list<const Token *> tokens = { declaration,definition };

lib/checkother.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class CPPCHECKLIB CheckOther : public Check {
256256
void unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef);
257257
void unknownEvaluationOrder(const Token* tok, bool isUnspecifiedBehavior = false);
258258
void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive);
259-
void funcArgNamesDifferent(const std::string & functionName, nonneg int index, const Token* declaration, const Token* definition);
259+
void funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition);
260260
void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions);
261261
void shadowError(const Token *var, const Token *shadowed, const std::string& type);
262262
void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden);

0 commit comments

Comments
 (0)