Skip to content

Commit e0014e1

Browse files
authored
fixed some -Wsign-compare compiler warnings (#8280)
1 parent a709c86 commit e0014e1

23 files changed

Lines changed: 76 additions & 76 deletions

lib/analyzerinfo.cpp

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

129-
std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fsFileId)
129+
std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId)
130130
{
131131
std::string line;
132132
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
@@ -90,11 +90,11 @@ void Check64BitPortabilityImpl::pointerassignment()
9090
if (!returnType)
9191
continue;
9292

93-
if (retPointer && !returnType->typeScope && returnType->pointer == 0U)
93+
if (retPointer && !returnType->typeScope && returnType->pointer == 0)
9494
returnIntegerError(tok);
9595

9696
if (!retPointer) {
97-
bool warn = returnType->pointer >= 1U;
97+
bool warn = returnType->pointer >= 1;
9898
if (!warn) {
9999
const Token* tok2 = tok->astOperand1();
100100
while (tok2 && tok2->isCast())
@@ -119,17 +119,17 @@ void Check64BitPortabilityImpl::pointerassignment()
119119
continue;
120120

121121
// Assign integer to pointer..
122-
if (lhstype->pointer >= 1U &&
122+
if (lhstype->pointer >= 1 &&
123123
!tok->astOperand2()->isNumber() &&
124-
rhstype->pointer == 0U &&
124+
rhstype->pointer == 0 &&
125125
rhstype->originalTypeName.empty() &&
126126
rhstype->type == ValueType::Type::INT &&
127127
!isFunctionPointer(tok->astOperand1()))
128128
assignmentIntegerToAddressError(tok);
129129

130130
// Assign pointer to integer..
131-
if (rhstype->pointer >= 1U &&
132-
lhstype->pointer == 0U &&
131+
if (rhstype->pointer >= 1 &&
132+
lhstype->pointer == 0 &&
133133
lhstype->originalTypeName.empty() &&
134134
lhstype->isIntegral() &&
135135
lhstype->type >= ValueType::Type::CHAR &&

lib/checkbufferoverrun.cpp

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

lib/checkclass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ bool CheckClassImpl::isMemberFunc(const Scope *scope, const Token *tok)
24142414
for (const Function &func : scope->functionList) {
24152415
if (func.name() == tok->str()) {
24162416
const Token* tok2 = tok->tokAt(2);
2417-
int argsPassed = tok2->str() == ")" ? 0 : 1;
2417+
size_t argsPassed = tok2->str() == ")" ? 0 : 1;
24182418
for (;;) {
24192419
tok2 = tok2->nextArgument();
24202420
if (tok2)
@@ -2511,9 +2511,9 @@ bool CheckClassImpl::checkConstFunc(const Scope *scope, const Function *func, Me
25112511

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

2516-
for (nonneg int argIndex = 0; argIndex < argMax; ++argIndex) {
2516+
for (size_t argIndex = 0; argIndex < argMax; ++argIndex) {
25172517
const Variable* const argVar = f->getArgumentVar(argIndex);
25182518
if (!argVar || ((argVar->isArrayOrPointer() || argVar->isReference()) &&
25192519
!(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 CheckFunctionsImpl::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
@@ -392,7 +392,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken,
392392
});
393393
});
394394
if (hasOutParam) {
395-
for (int i = 0; i < args.size(); i++) {
395+
for (size_t i = 0; i < args.size(); i++) {
396396
if (!argChecks.count(i + 1))
397397
continue;
398398
const ArgumentChecks argCheck = argChecks.at(i + 1);

lib/checknullpointer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static const CWE CWE_INCORRECT_CALCULATION(682U);
4949

5050
//---------------------------------------------------------------------------
5151

52-
static bool checkNullpointerFunctionCallPlausibility(const Function* func, unsigned int arg)
52+
static bool checkNullpointerFunctionCallPlausibility(const Function* func, size_t arg)
5353
{
5454
return !func || (func->argCount() >= arg && func->getArgumentVar(arg - 1) && func->getArgumentVar(arg - 1)->isPointer());
5555
}
@@ -61,7 +61,7 @@ std::list<const Token*> CheckNullPointerImpl::parseFunctionCall(const Token &tok
6161

6262
const std::vector<const Token *> args = getArguments(&tok);
6363
std::list<const Token*> var;
64-
for (int argnr = 1; argnr <= args.size(); ++argnr) {
64+
for (size_t argnr = 1; argnr <= args.size(); ++argnr) {
6565
const Token *param = args[argnr - 1];
6666
if ((!checkNullArg || library.isnullargbad(&tok, argnr)) && checkNullpointerFunctionCallPlausibility(tok.function(), argnr))
6767
var.push_back(param);
@@ -370,7 +370,7 @@ void CheckNullPointerImpl::nullConstantDereference()
370370

371371
else if (Token::Match(tok->previous(), "::|. %name% (")) {
372372
const std::vector<const Token *> &args = getArguments(tok);
373-
for (int argnr = 0; argnr < args.size(); ++argnr) {
373+
for (size_t argnr = 0; argnr < args.size(); ++argnr) {
374374
const Token *argtok = args[argnr];
375375
if (!argtok->hasKnownIntValue())
376376
continue;

lib/checkother.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,7 +3313,7 @@ static bool constructorTakesReference(const Scope * const classScope)
33133313
{
33143314
return std::any_of(classScope->functionList.begin(), classScope->functionList.end(), [&](const Function& constructor) {
33153315
if (constructor.isConstructor()) {
3316-
for (int argnr = 0U; argnr < constructor.argCount(); argnr++) {
3316+
for (size_t argnr = 0U; argnr < constructor.argCount(); argnr++) {
33173317
const Variable * const argVar = constructor.getArgumentVar(argnr);
33183318
if (argVar && argVar->isReference()) {
33193319
return true;
@@ -4036,7 +4036,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent()
40364036
std::vector<const Token *> declarations(function->argCount());
40374037
std::vector<const Token *> definitions(function->argCount());
40384038
const Token * decl = function->argDef->next();
4039-
for (int j = 0; j < function->argCount(); ++j) {
4039+
for (size_t j = 0; j < function->argCount(); ++j) {
40404040
// get the definition
40414041
const Variable * variable = function->getArgumentVar(j);
40424042
if (variable) {
@@ -4064,11 +4064,11 @@ void CheckOtherImpl::checkFuncArgNamesDifferent()
40644064
// check for different argument order
40654065
if (warning) {
40664066
bool order_different = false;
4067-
for (int j = 0; j < function->argCount(); ++j) {
4067+
for (size_t j = 0; j < function->argCount(); ++j) {
40684068
if (!declarations[j] || !definitions[j] || declarations[j]->str() == definitions[j]->str())
40694069
continue;
40704070

4071-
for (int k = 0; k < function->argCount(); ++k) {
4071+
for (size_t k = 0; k < function->argCount(); ++k) {
40724072
if (j != k && definitions[k] && declarations[j]->str() == definitions[k]->str()) {
40734073
order_different = true;
40744074
break;
@@ -4082,7 +4082,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent()
40824082
}
40834083
// check for different argument names
40844084
if (style && inconclusive) {
4085-
for (int j = 0; j < function->argCount(); ++j) {
4085+
for (size_t j = 0; j < function->argCount(); ++j) {
40864086
const bool warn = (declarations[j] != nullptr) != (definitions[j] != nullptr) ||
40874087
(declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str());
40884088
if (warn)
@@ -4092,7 +4092,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent()
40924092
}
40934093
}
40944094

4095-
void CheckOtherImpl::funcArgNamesDifferent(const std::string & functionName, nonneg int index,
4095+
void CheckOtherImpl::funcArgNamesDifferent(const std::string & functionName, size_t index,
40964096
const Token* declaration, const Token* definition)
40974097
{
40984098
std::list<const Token *> tokens = { declaration,definition };

lib/checkother.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class CPPCHECKLIB CheckOtherImpl : public CheckImpl {
316316
void unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef);
317317
void unknownEvaluationOrder(const Token* tok, bool isUnspecifiedBehavior = false);
318318
void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive);
319-
void funcArgNamesDifferent(const std::string & functionName, nonneg int index, const Token* declaration, const Token* definition);
319+
void funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition);
320320
void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions);
321321
void shadowError(const Token *shadows, const std::string &shadowsType, const Token *shadowed, const std::string &shadowedType);
322322
void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden);

0 commit comments

Comments
 (0)