Skip to content

Commit 362323c

Browse files
committed
fixed some -Wsign-compare compiler warnings
1 parent 9d674c2 commit 362323c

17 files changed

Lines changed: 42 additions & 42 deletions

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/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, nonneg int 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/checkstl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ void CheckStl::mismatchingContainers()
833833

834834
// Group args together by container
835835
std::map<int, std::vector<ArgIteratorInfo>> containers;
836-
for (int argnr = 1; argnr <= args.size(); ++argnr) {
836+
for (size_t argnr = 1; argnr <= args.size(); ++argnr) {
837837
const Library::ArgumentChecks::IteratorInfo *i = mSettings->library.getArgIteratorInfo(ftok, argnr);
838838
if (!i)
839839
continue;
@@ -1447,7 +1447,7 @@ void CheckStl::eraseCheckLoopVar(const Scope &scope, const Variable *var)
14471447
continue;
14481448
}
14491449
if (tok2->str() == "}") {
1450-
if (indentlevel > 0U)
1450+
if (indentlevel > 0)
14511451
--indentlevel;
14521452
else if (Token::simpleMatch(tok2, "} else {"))
14531453
tok2 = tok2->linkAt(2);
@@ -3242,7 +3242,7 @@ void CheckStl::knownEmptyContainer()
32423242
if (args.empty())
32433243
continue;
32443244

3245-
for (int argnr = 1; argnr <= args.size(); ++argnr) {
3245+
for (size_t argnr = 1; argnr <= args.size(); ++argnr) {
32463246
const Library::ArgumentChecks::IteratorInfo *i = mSettings->library.getArgIteratorInfo(tok, argnr);
32473247
if (!i)
32483248
continue;

lib/checktype.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void CheckType::checkIntegerOverflow()
186186
if (!vt || !vt->isIntegral() || vt->sign != ValueType::Sign::SIGNED)
187187
continue;
188188

189-
unsigned int bits;
189+
int bits;
190190
if (vt->type == ValueType::Type::INT)
191191
bits = mSettings->platform.int_bit;
192192
else if (vt->type == ValueType::Type::LONG)
@@ -213,7 +213,7 @@ void CheckType::checkIntegerOverflow()
213213
continue;
214214

215215
// For left shift, it's common practice to shift into the sign bit
216-
if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (static_cast<MathLib::biguint>(1) << bits))
216+
if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (1ULL << bits))
217217
continue;
218218

219219
integerOverflowError(tok, *value, isOverflow);

lib/clangimport.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static std::vector<std::string> splitString(const std::string &line)
140140
pos2 = line.find('\"', pos1+1);
141141
else if (line[pos1] == '\'') {
142142
pos2 = line.find('\'', pos1+1);
143-
if (pos2 < static_cast<int>(line.size()) - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)
143+
if (pos2 < line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)
144144
pos2 = line.find('\'', pos2 + 3);
145145
} else {
146146
pos2 = pos1;
@@ -357,7 +357,7 @@ namespace clangimport {
357357
/**
358358
* @throws InternalError thrown if index is out of bounds
359359
*/
360-
AstNodePtr getChild(int c) {
360+
AstNodePtr getChild(size_t c) {
361361
if (c >= children.size()) {
362362
std::ostringstream err;
363363
err << "ClangImport: AstNodePtr::getChild(" << c << ") out of bounds. children.size=" << children.size() << " " << nodeType;
@@ -509,7 +509,7 @@ void clangimport::AstNode::dumpAst(int num, int indent) const
509509
for (const auto& tok: mExtTokens)
510510
std::cout << " " << tok;
511511
std::cout << std::endl;
512-
for (int c = 0; c < children.size(); ++c) {
512+
for (size_t c = 0; c < children.size(); ++c) {
513513
if (children[c])
514514
children[c]->dumpAst(c, indent + 2);
515515
else
@@ -1432,7 +1432,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList)
14321432
function->nestedIn = nestedIn;
14331433
function->argDef = par1;
14341434
// Function arguments
1435-
for (int i = 0; i < children.size(); ++i) {
1435+
for (size_t i = 0; i < children.size(); ++i) {
14361436
AstNodePtr child = children[i];
14371437
if (child->nodeType != ParmVarDecl)
14381438
continue;
@@ -1657,7 +1657,7 @@ void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f)
16571657
continue;
16581658
}
16591659

1660-
const int level = (pos1 - 1) / 2;
1660+
const size_t level = (pos1 - 1) / 2;
16611661
if (level == 0 || level > tree.size())
16621662
continue;
16631663

lib/ctu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer &tokenizer)
330330
if (!tokFunction)
331331
continue;
332332
const std::vector<const Token *> args(getArguments(tok->previous()));
333-
for (int argnr = 0; argnr < args.size(); ++argnr) {
333+
for (size_t argnr = 0; argnr < args.size(); ++argnr) {
334334
const Token *argtok = args[argnr];
335335
if (!argtok)
336336
continue;

lib/fwdanalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
358358
ftok = ftok->astParent();
359359
if (ftok && Token::Match(ftok->previous(), "%name% (")) {
360360
const std::vector<const Token *> args = getArguments(ftok);
361-
int argnr = 0;
361+
size_t argnr = 0;
362362
while (argnr < args.size() && args[argnr] != parent)
363363
argnr++;
364364
if (argnr < args.size()) {
@@ -532,7 +532,7 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
532532
if (Token::Match(tok, "%name% (") && !Token::Match(tok, "if|while|for")) {
533533
// Is argument passed by reference?
534534
const std::vector<const Token*> args = getArguments(tok);
535-
for (int argnr = 0; argnr < args.size(); ++argnr) {
535+
for (size_t argnr = 0; argnr < args.size(); ++argnr) {
536536
if (!Token::Match(args[argnr], "%name%|.|::"))
537537
continue;
538538
if (tok->function() && tok->function()->getArgumentVar(argnr) && !tok->function()->getArgumentVar(argnr)->isReference() && !tok->function()->isConst())

0 commit comments

Comments
 (0)