diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 6f919ec3651..36803b897b1 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -126,7 +126,7 @@ std::string AnalyzerInformation::skipAnalysis(const tinyxml2::XMLDocument &analy return ""; } -std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fsFileId) +std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId) { std::string line; while (std::getline(filesTxt,line)) { diff --git a/lib/analyzerinfo.h b/lib/analyzerinfo.h index d2a83c747c3..75674a22f82 100644 --- a/lib/analyzerinfo.h +++ b/lib/analyzerinfo.h @@ -87,7 +87,7 @@ class CPPCHECKLIB AnalyzerInformation { protected: static std::string getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings); - static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, int fsFileId); + static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId); static std::string skipAnalysis(const tinyxml2::XMLDocument &analyzerInfoDoc, std::size_t hash, std::list &errors); diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index 345d66d9846..174237eef5a 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -90,11 +90,11 @@ void Check64BitPortabilityImpl::pointerassignment() if (!returnType) continue; - if (retPointer && !returnType->typeScope && returnType->pointer == 0U) + if (retPointer && !returnType->typeScope && returnType->pointer == 0) returnIntegerError(tok); if (!retPointer) { - bool warn = returnType->pointer >= 1U; + bool warn = returnType->pointer >= 1; if (!warn) { const Token* tok2 = tok->astOperand1(); while (tok2 && tok2->isCast()) @@ -119,17 +119,17 @@ void Check64BitPortabilityImpl::pointerassignment() continue; // Assign integer to pointer.. - if (lhstype->pointer >= 1U && + if (lhstype->pointer >= 1 && !tok->astOperand2()->isNumber() && - rhstype->pointer == 0U && + rhstype->pointer == 0 && rhstype->originalTypeName.empty() && rhstype->type == ValueType::Type::INT && !isFunctionPointer(tok->astOperand1())) assignmentIntegerToAddressError(tok); // Assign pointer to integer.. - if (rhstype->pointer >= 1U && - lhstype->pointer == 0U && + if (rhstype->pointer >= 1 && + lhstype->pointer == 0 && lhstype->originalTypeName.empty() && lhstype->isIntegral() && lhstype->type >= ValueType::Type::CHAR && diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index d278208fcc3..96b7ac9fdd0 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -646,7 +646,7 @@ void CheckBufferOverrunImpl::bufferOverflow() if (!mSettings.library.hasminsize(tok)) continue; const std::vector args = getArguments(tok); - for (int argnr = 0; argnr < args.size(); ++argnr) { + for (size_t argnr = 0; argnr < args.size(); ++argnr) { if (!args[argnr]->valueType() || args[argnr]->valueType()->pointer == 0) continue; const std::vector *minsizes = mSettings.library.argminsizes(tok, argnr + 1); @@ -838,7 +838,7 @@ void CheckBufferOverrunImpl::argumentSize() // If argument is '%type% a[num]' then check bounds against num const Function *callfunc = tok->function(); const std::vector callargs = getArguments(tok); - for (nonneg int paramIndex = 0; paramIndex < callargs.size() && paramIndex < callfunc->argCount(); ++paramIndex) { + for (size_t paramIndex = 0; paramIndex < callargs.size() && paramIndex < callfunc->argCount(); ++paramIndex) { const Variable* const argument = callfunc->getArgumentVar(paramIndex); if (!argument || !argument->nameToken() || !argument->isArray()) continue; diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 7d3fa5c51ec..ce96849ca27 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2414,7 +2414,7 @@ bool CheckClassImpl::isMemberFunc(const Scope *scope, const Token *tok) for (const Function &func : scope->functionList) { if (func.name() == tok->str()) { const Token* tok2 = tok->tokAt(2); - int argsPassed = tok2->str() == ")" ? 0 : 1; + size_t argsPassed = tok2->str() == ")" ? 0 : 1; for (;;) { tok2 = tok2->nextArgument(); if (tok2) @@ -2511,9 +2511,9 @@ bool CheckClassImpl::checkConstFunc(const Scope *scope, const Function *func, Me if (const Function* f = funcTok->function()) { // check known function const std::vector args = getArguments(funcTok); - const auto argMax = std::min(args.size(), f->argCount()); + const auto argMax = std::min(args.size(), f->argCount()); - for (nonneg int argIndex = 0; argIndex < argMax; ++argIndex) { + for (size_t argIndex = 0; argIndex < argMax; ++argIndex) { const Variable* const argVar = f->getArgumentVar(argIndex); if (!argVar || ((argVar->isArrayOrPointer() || argVar->isReference()) && !(argVar->valueType() && argVar->valueType()->isConst(argVar->valueType()->pointer)))) { // argument might be modified diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index d04f9d9cc1d..23db248816d 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -116,7 +116,7 @@ void CheckFunctionsImpl::invalidFunctionUsage() continue; const Token * const functionToken = tok; const std::vector arguments = getArguments(tok); - for (int argnr = 1; argnr <= arguments.size(); ++argnr) { + for (size_t argnr = 1; argnr <= arguments.size(); ++argnr) { const Token * const argtok = arguments[argnr-1]; // check ... diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 2fd16e85eaa..9049d56e7ff 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -392,7 +392,7 @@ bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, }); }); if (hasOutParam) { - for (int i = 0; i < args.size(); i++) { + for (size_t i = 0; i < args.size(); i++) { if (!argChecks.count(i + 1)) continue; const ArgumentChecks argCheck = argChecks.at(i + 1); diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 9790f7f2724..ac56f19eb09 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -49,7 +49,7 @@ static const CWE CWE_INCORRECT_CALCULATION(682U); //--------------------------------------------------------------------------- -static bool checkNullpointerFunctionCallPlausibility(const Function* func, unsigned int arg) +static bool checkNullpointerFunctionCallPlausibility(const Function* func, size_t arg) { return !func || (func->argCount() >= arg && func->getArgumentVar(arg - 1) && func->getArgumentVar(arg - 1)->isPointer()); } @@ -61,7 +61,7 @@ std::list CheckNullPointerImpl::parseFunctionCall(const Token &tok const std::vector args = getArguments(&tok); std::list var; - for (int argnr = 1; argnr <= args.size(); ++argnr) { + for (size_t argnr = 1; argnr <= args.size(); ++argnr) { const Token *param = args[argnr - 1]; if ((!checkNullArg || library.isnullargbad(&tok, argnr)) && checkNullpointerFunctionCallPlausibility(tok.function(), argnr)) var.push_back(param); @@ -370,7 +370,7 @@ void CheckNullPointerImpl::nullConstantDereference() else if (Token::Match(tok->previous(), "::|. %name% (")) { const std::vector &args = getArguments(tok); - for (int argnr = 0; argnr < args.size(); ++argnr) { + for (size_t argnr = 0; argnr < args.size(); ++argnr) { const Token *argtok = args[argnr]; if (!argtok->hasKnownIntValue()) continue; diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b5fd0dda361..bdaa12df7c5 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3311,7 +3311,7 @@ static bool constructorTakesReference(const Scope * const classScope) { return std::any_of(classScope->functionList.begin(), classScope->functionList.end(), [&](const Function& constructor) { if (constructor.isConstructor()) { - for (int argnr = 0U; argnr < constructor.argCount(); argnr++) { + for (size_t argnr = 0U; argnr < constructor.argCount(); argnr++) { const Variable * const argVar = constructor.getArgumentVar(argnr); if (argVar && argVar->isReference()) { return true; @@ -4034,7 +4034,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent() std::vector declarations(function->argCount()); std::vector definitions(function->argCount()); const Token * decl = function->argDef->next(); - for (int j = 0; j < function->argCount(); ++j) { + for (size_t j = 0; j < function->argCount(); ++j) { // get the definition const Variable * variable = function->getArgumentVar(j); if (variable) { @@ -4062,11 +4062,11 @@ void CheckOtherImpl::checkFuncArgNamesDifferent() // check for different argument order if (warning) { bool order_different = false; - for (int j = 0; j < function->argCount(); ++j) { + for (size_t j = 0; j < function->argCount(); ++j) { if (!declarations[j] || !definitions[j] || declarations[j]->str() == definitions[j]->str()) continue; - for (int k = 0; k < function->argCount(); ++k) { + for (size_t k = 0; k < function->argCount(); ++k) { if (j != k && definitions[k] && declarations[j]->str() == definitions[k]->str()) { order_different = true; break; @@ -4080,7 +4080,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent() } // check for different argument names if (style && inconclusive) { - for (int j = 0; j < function->argCount(); ++j) { + for (size_t j = 0; j < function->argCount(); ++j) { const bool warn = (declarations[j] != nullptr) != (definitions[j] != nullptr) || (declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str()); if (warn) @@ -4090,7 +4090,7 @@ void CheckOtherImpl::checkFuncArgNamesDifferent() } } -void CheckOtherImpl::funcArgNamesDifferent(const std::string & functionName, nonneg int index, +void CheckOtherImpl::funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition) { std::list tokens = { declaration,definition }; diff --git a/lib/checkother.h b/lib/checkother.h index 58a61ff772a..5c2c7948721 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -320,7 +320,7 @@ class CPPCHECKLIB CheckOtherImpl : public CheckImpl { void unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef); void unknownEvaluationOrder(const Token* tok, bool isUnspecifiedBehavior = false); void accessMovedError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive); - void funcArgNamesDifferent(const std::string & functionName, nonneg int index, const Token* declaration, const Token* definition); + void funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition); void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector & declarations, const std::vector & definitions); void shadowError(const Token *shadows, const std::string &shadowsType, const Token *shadowed, const std::string &shadowedType); void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden); diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index c8fcca48f1a..736c3043e3a 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -828,7 +828,7 @@ void CheckStlImpl::mismatchingContainers() // Group args together by container std::map> containers; - for (int argnr = 1; argnr <= args.size(); ++argnr) { + for (size_t argnr = 1; argnr <= args.size(); ++argnr) { const Library::ArgumentChecks::IteratorInfo *i = mSettings.library.getArgIteratorInfo(ftok, argnr); if (!i) continue; @@ -1433,7 +1433,7 @@ void CheckStlImpl::eraseCheckLoopVar(const Scope &scope, const Variable *var) if (Token::Match(tok->astParent(), "=|return")) continue; // Iterator is invalid.. - int indentlevel = 0U; + int indentlevel = 0; const Token *tok2 = tok->link(); for (; tok2 != scope.bodyEnd; tok2 = tok2->next()) { if (tok2->str() == "{") { @@ -1441,7 +1441,7 @@ void CheckStlImpl::eraseCheckLoopVar(const Scope &scope, const Variable *var) continue; } if (tok2->str() == "}") { - if (indentlevel > 0U) + if (indentlevel > 0) --indentlevel; else if (Token::simpleMatch(tok2, "} else {")) tok2 = tok2->linkAt(2); @@ -3294,7 +3294,7 @@ void CheckStlImpl::knownEmptyContainer() if (args.empty()) continue; - for (int argnr = 1; argnr <= args.size(); ++argnr) { + for (size_t argnr = 1; argnr <= args.size(); ++argnr) { const Library::ArgumentChecks::IteratorInfo *i = mSettings.library.getArgIteratorInfo(tok, argnr); if (!i) continue; diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index c96a678347a..236d0ae7133 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -140,7 +140,7 @@ static std::vector splitString(const std::string &line) pos2 = line.find('\"', pos1+1); else if (line[pos1] == '\'') { pos2 = line.find('\'', pos1+1); - if (pos2 < static_cast(line.size()) - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) + if (pos2 < line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) pos2 = line.find('\'', pos2 + 3); } else { pos2 = pos1; @@ -357,7 +357,7 @@ namespace clangimport { /** * @throws InternalError thrown if index is out of bounds */ - AstNodePtr getChild(int c) { + AstNodePtr getChild(size_t c) { if (c >= children.size()) { std::ostringstream err; 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 for (const auto& tok: mExtTokens) std::cout << " " << tok; std::cout << std::endl; - for (int c = 0; c < children.size(); ++c) { + for (size_t c = 0; c < children.size(); ++c) { if (children[c]) children[c]->dumpAst(c, indent + 2); else @@ -1432,7 +1432,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList &tokenList) function->nestedIn = nestedIn; function->argDef = par1; // Function arguments - for (int i = 0; i < children.size(); ++i) { + for (size_t i = 0; i < children.size(); ++i) { AstNodePtr child = children[i]; if (child->nodeType != ParmVarDecl) continue; @@ -1657,7 +1657,7 @@ void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f) continue; } - const int level = (pos1 - 1) / 2; + const size_t level = (pos1 - 1) / 2; if (level == 0 || level > tree.size()) continue; diff --git a/lib/ctu.cpp b/lib/ctu.cpp index fee3acb85ae..feef065d3ac 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -280,11 +280,11 @@ std::list CTU::loadUnsafeUsageListFromXml(const tiny return ret; } -static int isCallFunction(const Scope *scope, int argnr, const Token *&tok) +static size_t isCallFunction(const Scope *scope, size_t argnr, const Token *&tok) { const Variable * const argvar = scope->function->getArgumentVar(argnr); if (!argvar->isPointer()) - return -1; + return 0; for (const Token *tok2 = scope->bodyStart; tok2 != scope->bodyEnd; tok2 = tok2->next()) { if (tok2->variable() != argvar) continue; @@ -306,7 +306,7 @@ static int isCallFunction(const Scope *scope, int argnr, const Token *&tok) tok = prev->previous(); return argnr2; } - return -1; + return 0; } @@ -330,7 +330,7 @@ const CTU::FileInfo *CTU::getFileInfo(const Tokenizer &tokenizer) if (!tokFunction) continue; const std::vector args(getArguments(tok->previous())); - for (int argnr = 0; argnr < args.size(); ++argnr) { + for (size_t argnr = 0; argnr < args.size(); ++argnr) { const Token *argtok = args[argnr]; if (!argtok) continue; @@ -427,9 +427,9 @@ const CTU::FileInfo *CTU::getFileInfo(const Tokenizer &tokenizer) } // Nested function calls - for (int argnr = 0; argnr < scopeFunction->argCount(); ++argnr) { + for (size_t argnr = 0; argnr < scopeFunction->argCount(); ++argnr) { const Token *tok; - const int argnr2 = isCallFunction(&scope, argnr, tok); + const size_t argnr2 = isCallFunction(&scope, argnr, tok); if (argnr2 > 0) { FileInfo::NestedCall nestedCall(tokenizer, scopeFunction, tok); nestedCall.myArgNr = argnr + 1; @@ -442,7 +442,7 @@ const CTU::FileInfo *CTU::getFileInfo(const Tokenizer &tokenizer) return fileInfo; } -static std::vector> getUnsafeFunction(const Settings &settings, const Scope *scope, int argnr, bool (*isUnsafeUsage)(const Settings &settings, const Token *argtok, CTU::FileInfo::Value *value)) +static std::vector> getUnsafeFunction(const Settings &settings, const Scope *scope, size_t argnr, bool (*isUnsafeUsage)(const Settings &settings, const Token *argtok, CTU::FileInfo::Value *value)) { std::vector> ret; const Variable * const argvar = scope->function->getArgumentVar(argnr); @@ -487,7 +487,7 @@ std::list CTU::getUnsafeUsage(const Tokenizer &token const Function *const function = scope.function; // "Unsafe" functions unconditionally reads data before it is written.. - for (int argnr = 0; argnr < function->argCount(); ++argnr) { + for (size_t argnr = 0; argnr < function->argCount(); ++argnr) { for (const std::pair &v : getUnsafeFunction(settings, &scope, argnr, isUnsafeUsage)) { const Token *tok = v.first; const MathLib::bigint val = v.second.value; @@ -500,7 +500,7 @@ std::list CTU::getUnsafeUsage(const Tokenizer &token } static bool findPath(const std::string &callId, - nonneg int callArgNr, + size_t callArgNr, MathLib::bigint unsafeValue, CTU::FileInfo::InvalidValueType invalidValue, const std::map> &callsMap, diff --git a/lib/ctu.h b/lib/ctu.h index 60120064284..76baff21b9f 100644 --- a/lib/ctu.h +++ b/lib/ctu.h @@ -79,14 +79,14 @@ namespace CTU { struct UnsafeUsage { UnsafeUsage() = default; - UnsafeUsage(std::string myId, nonneg int myArgNr, std::string myArgumentName, Location location, MathLib::bigint value) + UnsafeUsage(std::string myId, size_t myArgNr, std::string myArgumentName, Location location, MathLib::bigint value) : myId(std::move(myId)) , myArgNr(myArgNr) , myArgumentName(std::move(myArgumentName)) , location(std::move(location)) , value(value) {} std::string myId; - nonneg int myArgNr{}; + size_t myArgNr{}; std::string myArgumentName; Location location; MathLib::bigint value{}; @@ -96,14 +96,14 @@ namespace CTU { class CallBase { public: CallBase() = default; - CallBase(std::string callId, int callArgNr, std::string callFunctionName, Location loc) + CallBase(std::string callId, size_t callArgNr, std::string callFunctionName, Location loc) : callId(std::move(callId)), callArgNr(callArgNr), callFunctionName(std::move(callFunctionName)), location(std::move(loc)) {} CallBase(const Tokenizer &tokenizer, const Token *callToken); virtual ~CallBase() = default; CallBase(const CallBase&) = default; std::string callId; - int callArgNr{}; + size_t callArgNr{}; std::string callFunctionName; Location location; protected: @@ -138,7 +138,7 @@ namespace CTU { bool loadFromXml(const tinyxml2::XMLElement *xmlElement); std::string myId; - nonneg int myArgNr{}; + size_t myArgNr{}; }; std::list functionCalls; diff --git a/lib/errorlogger.h b/lib/errorlogger.h index d739cb3fbf9..daf683bd0a3 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -88,7 +88,7 @@ class CPPCHECKLIB ErrorMessage { std::string stringify(bool addcolumn = false) const; unsigned int fileIndex; - int line; // negative value means "no line" + int line; // negative value means "no line" - TODO: actually 0 means no line - lines from simplecpp are unsigned unsigned int column; const std::string& getinfo() const { diff --git a/lib/fwdanalysis.cpp b/lib/fwdanalysis.cpp index c45213a4be9..c3c52d178c9 100644 --- a/lib/fwdanalysis.cpp +++ b/lib/fwdanalysis.cpp @@ -358,7 +358,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token * ftok = ftok->astParent(); if (ftok && Token::Match(ftok->previous(), "%name% (")) { const std::vector args = getArguments(ftok); - int argnr = 0; + size_t argnr = 0; while (argnr < args.size() && args[argnr] != parent) argnr++; if (argnr < args.size()) { @@ -542,7 +542,7 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co if (Token::Match(tok, "%name% (") && !Token::Match(tok, "if|while|for")) { // Is argument passed by reference? const std::vector args = getArguments(tok); - for (int argnr = 0; argnr < args.size(); ++argnr) { + for (size_t argnr = 0; argnr < args.size(); ++argnr) { if (!Token::Match(args[argnr], "%name%|.|::")) continue; if (tok->function() && tok->function()->getArgumentVar(argnr) && !tok->function()->getArgumentVar(argnr)->isReference() && !tok->function()->isConst()) diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index e1f40de277e..b86ca2d8812 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -1552,7 +1552,7 @@ namespace { return unknown(); const MathLib::bigint index = rhs.intvalue; if (index >= 0 && index < strValue.size()) - return ValueFlow::Value{strValue[static_cast(index)]}; + return ValueFlow::Value{strValue[index]}; if (index == strValue.size()) return ValueFlow::Value{}; } else if (Token::Match(expr, "%cop%") && expr->astOperand1() && expr->astOperand2()) { diff --git a/lib/reverseanalyzer.cpp b/lib/reverseanalyzer.cpp index 4afd2556a24..38aea656bf0 100644 --- a/lib/reverseanalyzer.cpp +++ b/lib/reverseanalyzer.cpp @@ -204,7 +204,7 @@ namespace { void traverse(Token* start, const Token* end = nullptr) { if (start == end) return; - std::size_t i = start->index(); + nonneg int i = start->index(); for (Token* tok = start->previous(); succeeds(tok, end); tok = tok->previous()) { if (tok->index() >= i) throw InternalError(tok, "Cyclic reverse analysis."); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index dda3e9b1e0b..71225bdbf44 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2173,7 +2173,7 @@ namespace { { if (const Scope* scope = var->nameToken()->scope()) { auto it = std::find_if(scope->functionList.begin(), scope->functionList.end(), [&](const Function& function) { - for (nonneg int arg = 0; arg < function.argCount(); ++arg) { + for (size_t arg = 0; arg < function.argCount(); ++arg) { if (var == function.getArgumentVar(arg)) return true; } @@ -4536,7 +4536,7 @@ void SymbolDatabase::printXml(std::ostream &out) const outs += "/>\n"; else { outs += ">\n"; - for (unsigned int argnr = 0; argnr < function->argCount(); ++argnr) { + for (size_t argnr = 0; argnr < function->argCount(); ++argnr) { const Variable *arg = function->getArgumentVar(argnr); outs += " & matches) const +void Scope::findFunctionInBase(const Token* tok, size_t args, std::vector & matches) const { if (isClassOrStruct() && definedType && !definedType->derivedFrom.empty()) { const std::vector &derivedFrom = definedType->derivedFrom; @@ -7049,7 +7049,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const return; } - if (parent->str() == "[" && (!parent->isCpp() || parent->astOperand1() == tok) && valuetype.pointer > 0U && !Token::Match(parent->previous(), "[{,]")) { + if (parent->str() == "[" && (!parent->isCpp() || parent->astOperand1() == tok) && valuetype.pointer > 0 && !Token::Match(parent->previous(), "[{,]")) { const Token *op1 = parent->astOperand1(); while (op1 && op1->str() == "[") op1 = op1->astOperand1(); @@ -7061,7 +7061,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const setValueType(parent, vt); return; } - if (Token::Match(parent->tokAt(-1), "%name% (") && !parent->tokAt(-1)->isKeyword() && parent->astOperand1() == tok && valuetype.pointer > 0U) { + if (Token::Match(parent->tokAt(-1), "%name% (") && !parent->tokAt(-1)->isKeyword() && parent->astOperand1() == tok && valuetype.pointer > 0) { ValueType vt(valuetype); vt.pointer -= 1U; setValueType(parent, vt); @@ -7074,7 +7074,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const setValueType(parent, vt); return; } - if (parent->str() == "*" && !parent->astOperand2() && valuetype.pointer > 0U) { + if (parent->str() == "*" && !parent->astOperand2() && valuetype.pointer > 0) { ValueType vt(valuetype); vt.pointer -= 1U; setValueType(parent, vt); @@ -7107,7 +7107,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, const return; } } - if (parent->str() == "*" && Token::simpleMatch(parent->astOperand2(), "[") && valuetype.pointer > 0U) { + if (parent->str() == "*" && Token::simpleMatch(parent->astOperand2(), "[") && valuetype.pointer > 0) { const Token *op1 = parent->astOperand2()->astOperand1(); while (op1 && op1->str() == "[") op1 = op1->astOperand1(); @@ -8714,7 +8714,7 @@ std::string ValueType::str() const } else if (type == ValueType::Type::SMART_POINTER && smartPointer) { ret += " smart-pointer(" + smartPointer->name + ")"; } - for (unsigned int p = 0; p < pointer; p++) { + for (nonneg int p = 0; p < pointer; p++) { ret += " *"; if (constness & (2 << p)) ret += " const"; diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index a4a07fd2083..166f228ad99 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -767,14 +767,14 @@ class CPPCHECKLIB Function { std::string fullName() const; - nonneg int argCount() const { + size_t argCount() const { return argumentList.size(); } - nonneg int minArgCount() const { + size_t minArgCount() const { return argumentList.size() - initArgCount; } - const Variable* getArgumentVar(nonneg int num) const; - nonneg int initializedArgCount() const { + const Variable* getArgumentVar(size_t num) const; + size_t initializedArgCount() const { return initArgCount; } /** @@ -928,7 +928,7 @@ class CPPCHECKLIB Function { const Scope* functionScope{}; ///< scope of function body const Scope* nestedIn{}; ///< Scope the function is declared in std::list argumentList; ///< argument list, must remain list due to clangimport usage! - nonneg int initArgCount{}; ///< number of args with default values + size_t initArgCount{}; ///< number of args with default values FunctionType type = FunctionType::eFunction; ///< constructor, destructor, ... const Token* noexceptArg{}; ///< noexcept token const Token* throwArg{}; ///< throw token @@ -1209,7 +1209,7 @@ class CPPCHECKLIB Scope { */ bool isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const; - void findFunctionInBase(const Token* tok, nonneg int args, std::vector & matches) const; + void findFunctionInBase(const Token* tok, size_t args, std::vector & matches) const; /** @brief initialize varlist */ void getVariableList(const Token *start, const Token *end); diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 1fe1df10037..ef9fbcb50a7 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2258,7 +2258,7 @@ void TemplateSimplifier::expandTemplate( Token::Match(tok3->next()->findClosingBracket(), ">|>>")) { const Token *closingBracket = tok3->next()->findClosingBracket(); if (Token::simpleMatch(closingBracket->next(), "&")) { - int num = 0; + size_t num = 0; const Token *par = tok3->next(); while (num < typeParametersInDeclaration.size() && par != closingBracket) { const std::string pattern("[<,] " + typeParametersInDeclaration[num]->str() + " [,>]"); @@ -3041,7 +3041,7 @@ bool TemplateSimplifier::matchSpecialization( declToken->isSigned() != instToken->isSigned() || declToken->isUnsigned() != instToken->isUnsigned() || declToken->isLong() != instToken->isLong()) { - int nr = 0; + size_t nr = 0; while (nr < templateParameters.size() && templateParameters[nr]->str() != declToken->str()) ++nr; @@ -3139,7 +3139,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( // locate template usage.. std::string::size_type numberOfTemplateInstantiations = mTemplateInstantiations.size(); - unsigned int recursiveCount = 0; + int recursiveCount = 0; bool instantiated = false; diff --git a/lib/token.cpp b/lib/token.cpp index 2b30419b9df..b7f9268f8a8 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1331,10 +1331,10 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec std::string ret; - unsigned int lineNumber = mImpl->mLineNumber - (options.linenumbers ? 1U : 0U); + nonneg int lineNumber = mImpl->mLineNumber - (options.linenumbers ? 1 : 0); // cppcheck-suppress shadowFunction - TODO: fix this - unsigned int fileIndex = options.files ? ~0U : mImpl->mFileIndex; - std::map lineNumbers; + nonneg int fileIndex = options.files ? ~0U : mImpl->mFileIndex; + std::map lineNumbers; for (const Token *tok = this; tok != end; tok = tok->next()) { assert(tok && "end precedes token"); if (!tok) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 64a48285fdc..919d354b1de 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2459,7 +2459,7 @@ static void valueFlowLifetimeFunction(Token *tok, const TokenList &tokenlist, Er const int returnContainer = settings.library.returnValueContainer(tok); if (returnContainer >= 0) { std::vector args = getArguments(tok); - for (int argnr = 1; argnr <= args.size(); ++argnr) { + for (size_t argnr = 1; argnr <= args.size(); ++argnr) { const Library::ArgumentChecks::IteratorInfo *i = settings.library.getArgIteratorInfo(tok, argnr); if (!i) continue; @@ -5755,7 +5755,7 @@ static void valueFlowFunctionDefaultParameter(const TokenList& tokenlist, const const Function* function = scope->function; if (!function) continue; - for (nonneg int arg = function->minArgCount(); arg < function->argCount(); arg++) { + for (size_t arg = function->minArgCount(); arg < function->argCount(); arg++) { const Variable* var = function->getArgumentVar(arg); if (var && var->hasDefault() && Token::Match(var->nameToken(), "%var% = %num%|%str%|%char%|%name% [,)]")) { const std::list &values = var->nameToken()->tokAt(2)->values();