Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/analyzerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/analyzerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CPPCHECKLIB AnalyzerInformation {
protected:
static std::string getFilesTxt(const std::list<std::string> &sourcefiles, const std::list<FileSettings> &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<ErrorMessage> &errors);

Expand Down
12 changes: 6 additions & 6 deletions lib/check64bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ void Check64BitPortability::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())
Expand All @@ -124,17 +124,17 @@ void Check64BitPortability::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 &&
Expand Down
4 changes: 2 additions & 2 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ void CheckBufferOverrun::bufferOverflow()
if (!mSettings->library.hasminsize(tok))
continue;
const std::vector<const Token *> 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<Library::ArgumentChecks::MinSize> *minsizes = mSettings->library.argminsizes(tok, argnr + 1);
Expand Down Expand Up @@ -844,7 +844,7 @@ void CheckBufferOverrun::argumentSize()
// If argument is '%type% a[num]' then check bounds against num
const Function *callfunc = tok->function();
const std::vector<const Token *> 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;
Expand Down
6 changes: 3 additions & 3 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,7 @@ bool CheckClass::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)
Expand Down Expand Up @@ -2455,9 +2455,9 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member

if (const Function* f = funcTok->function()) { // check known function
const std::vector<const Token*> args = getArguments(funcTok);
const auto argMax = std::min<nonneg int>(args.size(), f->argCount());
const auto argMax = std::min<size_t>(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
Expand Down
2 changes: 1 addition & 1 deletion lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void CheckFunctions::invalidFunctionUsage()
continue;
const Token * const functionToken = tok;
const std::vector<const Token *> 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 <valid>...</valid>
Expand Down
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ bool CheckLeakAutoVar::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);
Expand Down
6 changes: 3 additions & 3 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace {

//---------------------------------------------------------------------------

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());
}
Expand All @@ -73,7 +73,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token

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

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);
Expand Down Expand Up @@ -390,7 +390,7 @@ void CheckNullPointer::nullConstantDereference()

else if (Token::Match(tok->previous(), "::|. %name% (")) {
const std::vector<const Token *> &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;
Expand Down
12 changes: 6 additions & 6 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3291,7 +3291,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;
Expand Down Expand Up @@ -4014,7 +4014,7 @@ void CheckOther::checkFuncArgNamesDifferent()
std::vector<const Token *> declarations(function->argCount());
std::vector<const Token *> 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) {
declarations[j] = nullptr;
definitions[j] = nullptr;
// get the definition
Expand Down Expand Up @@ -4044,11 +4044,11 @@ void CheckOther::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;
Expand All @@ -4062,15 +4062,15 @@ void CheckOther::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) {
if (declarations[j] && definitions[j] && declarations[j]->str() != definitions[j]->str())
funcArgNamesDifferent(function->name(), j, declarations[j], definitions[j]);
}
}
}
}

void CheckOther::funcArgNamesDifferent(const std::string & functionName, nonneg int index,
void CheckOther::funcArgNamesDifferent(const std::string & functionName, size_t index,
const Token* declaration, const Token* definition)
{
std::list<const Token *> tokens = { declaration,definition };
Expand Down
2 changes: 1 addition & 1 deletion lib/checkother.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class CPPCHECKLIB CheckOther : public Check {
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<const Token*> & declarations, const std::vector<const Token*> & definitions);
void shadowError(const Token *var, const Token *shadowed, const std::string& type);
void knownArgumentError(const Token *tok, const Token *ftok, const ValueFlow::Value *value, const std::string &varexpr, bool isVariableExpressionHidden);
Expand Down
8 changes: 4 additions & 4 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ void CheckStl::mismatchingContainers()

// Group args together by container
std::map<int, std::vector<ArgIteratorInfo>> 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;
Expand Down Expand Up @@ -1439,15 +1439,15 @@ void CheckStl::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() == "{") {
++indentlevel;
continue;
}
if (tok2->str() == "}") {
if (indentlevel > 0U)
if (indentlevel > 0)
--indentlevel;
else if (Token::simpleMatch(tok2, "} else {"))
tok2 = tok2->linkAt(2);
Expand Down Expand Up @@ -3242,7 +3242,7 @@ void CheckStl::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;
Expand Down
10 changes: 5 additions & 5 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static std::vector<std::string> splitString(const std::string &line)
pos2 = line.find('\"', pos1+1);
else if (line[pos1] == '\'') {
pos2 = line.find('\'', pos1+1);
if (pos2 < static_cast<int>(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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 9 additions & 9 deletions lib/ctu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ std::list<CTU::FileInfo::UnsafeUsage> 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;
Expand All @@ -306,7 +306,7 @@ static int isCallFunction(const Scope *scope, int argnr, const Token *&tok)
tok = prev->previous();
return argnr2;
}
return -1;
return 0;
}


Expand All @@ -330,7 +330,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer &tokenizer)
if (!tokFunction)
continue;
const std::vector<const Token *> 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;
Expand Down Expand Up @@ -427,9 +427,9 @@ 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;
Expand All @@ -442,7 +442,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer &tokenizer)
return fileInfo;
}

static std::vector<std::pair<const Token *, CTU::FileInfo::Value>> getUnsafeFunction(const Settings &settings, const Scope *scope, int argnr, bool (*isUnsafeUsage)(const Settings &settings, const Token *argtok, CTU::FileInfo::Value *value))
static std::vector<std::pair<const Token *, CTU::FileInfo::Value>> getUnsafeFunction(const Settings &settings, const Scope *scope, size_t argnr, bool (*isUnsafeUsage)(const Settings &settings, const Token *argtok, CTU::FileInfo::Value *value))
{
std::vector<std::pair<const Token *, CTU::FileInfo::Value>> ret;
const Variable * const argvar = scope->function->getArgumentVar(argnr);
Expand Down Expand Up @@ -487,7 +487,7 @@ std::list<CTU::FileInfo::UnsafeUsage> 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<const Token *, CTU::FileInfo::Value> &v : getUnsafeFunction(settings, &scope, argnr, isUnsafeUsage)) {
const Token *tok = v.first;
const MathLib::bigint val = v.second.value;
Expand All @@ -500,7 +500,7 @@ std::list<CTU::FileInfo::UnsafeUsage> 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<std::string, std::list<const CTU::FileInfo::CallBase *>> &callsMap,
Expand Down
Loading