Attempt to fix 2 Coverity messages.
Replace a few unsigned int by std::size_t
This commit is contained in:
parent
987ce5a408
commit
9b38ae73c1
|
@ -451,19 +451,20 @@ static fpSymFunctionTableAccess64 pSymFunctionTableAccess64;
|
|||
typedef BOOL (WINAPI *fpSymInitialize)(HANDLE, PCSTR, BOOL);
|
||||
static fpSymInitialize pSymInitialize;
|
||||
|
||||
static HMODULE hLibDbgHelp;
|
||||
// avoid explicit dependency on Dbghelp.dll
|
||||
static bool loadDbgHelp()
|
||||
{
|
||||
HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll");
|
||||
if (!hLib)
|
||||
hLibDbgHelp = ::LoadLibraryW(L"Dbghelp.dll");
|
||||
if (!hLibDbgHelp)
|
||||
return true;
|
||||
pStackWalk64 = (fpStackWalk64) ::GetProcAddress(hLib, "StackWalk64");
|
||||
pSymGetModuleBase64 = (fpSymGetModuleBase64) ::GetProcAddress(hLib, "SymGetModuleBase64");
|
||||
pSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) ::GetProcAddress(hLib, "SymGetSymFromAddr64");
|
||||
pSymGetLineFromAddr64 = (fpSymGetLineFromAddr64)::GetProcAddress(hLib, "SymGetLineFromAddr64");
|
||||
pSymFunctionTableAccess64 = (fpSymFunctionTableAccess64)::GetProcAddress(hLib, "SymFunctionTableAccess64");
|
||||
pSymInitialize = (fpSymInitialize) ::GetProcAddress(hLib, "SymInitialize");
|
||||
pUnDecorateSymbolName = (fpUnDecorateSymbolName)::GetProcAddress(hLib, "UnDecorateSymbolName");
|
||||
pStackWalk64 = (fpStackWalk64) ::GetProcAddress(hLibDbgHelp, "StackWalk64");
|
||||
pSymGetModuleBase64 = (fpSymGetModuleBase64) ::GetProcAddress(hLibDbgHelp, "SymGetModuleBase64");
|
||||
pSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) ::GetProcAddress(hLibDbgHelp, "SymGetSymFromAddr64");
|
||||
pSymGetLineFromAddr64 = (fpSymGetLineFromAddr64)::GetProcAddress(hLibDbgHelp, "SymGetLineFromAddr64");
|
||||
pSymFunctionTableAccess64 = (fpSymFunctionTableAccess64)::GetProcAddress(hLibDbgHelp, "SymFunctionTableAccess64");
|
||||
pSymInitialize = (fpSymInitialize) ::GetProcAddress(hLibDbgHelp, "SymInitialize");
|
||||
pUnDecorateSymbolName = (fpUnDecorateSymbolName)::GetProcAddress(hLibDbgHelp, "UnDecorateSymbolName");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -520,7 +521,7 @@ static void PrintCallstack(FILE* f, PEXCEPTION_POINTERS ex)
|
|||
);
|
||||
if (!result) // official end...
|
||||
break;
|
||||
result = pSymGetSymFromAddr64(hProcess, (ULONG64)stack.AddrPC.Offset, &displacement, &symbol);
|
||||
pSymGetSymFromAddr64(hProcess, (ULONG64)stack.AddrPC.Offset, &displacement, &symbol);
|
||||
TCHAR undname[maxnamelength]= {0};
|
||||
pUnDecorateSymbolName((const TCHAR*)symbol.Name, (PTSTR)undname, (DWORD)GetArrayLength(undname), UNDNAME_COMPLETE);
|
||||
if (beyond_main>=0)
|
||||
|
@ -535,6 +536,9 @@ static void PrintCallstack(FILE* f, PEXCEPTION_POINTERS ex)
|
|||
if (0==stack.AddrReturn.Offset || beyond_main>2) // StackWalk64() sometimes doesn't reach any end...
|
||||
break;
|
||||
}
|
||||
|
||||
FreeLibrary(hLibDbgHelp);
|
||||
hLibDbgHelp=0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -491,7 +491,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
const unsigned int declarationId = arrayInfo.declarationId();
|
||||
|
||||
std::string varnames;
|
||||
for (unsigned int i = 0; i < varname.size(); ++i)
|
||||
for (std::size_t i = 0; i < varname.size(); ++i)
|
||||
varnames += (i == 0 ? "" : " . ") + varname[i];
|
||||
|
||||
const unsigned char varcount = static_cast<unsigned char>(varname.empty() ? 0U : (varname.size() - 1) * 2U);
|
||||
|
@ -553,8 +553,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
MathLib::bigint totalIndex = 0;
|
||||
|
||||
// calculate the totalElements and totalIndex..
|
||||
for (unsigned int i = 0; i < indexes.size(); ++i) {
|
||||
std::size_t ri = indexes.size() - 1 - i;
|
||||
for (std::size_t i = 0; i < indexes.size(); ++i) {
|
||||
const std::size_t ri = indexes.size() - 1 - i;
|
||||
totalIndex += indexes[ri] * totalElements;
|
||||
totalElements *= arrayInfo.num(ri);
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
// Is any array index out of bounds?
|
||||
else {
|
||||
// check each index for overflow
|
||||
for (unsigned int i = 0; i < indexes.size(); ++i) {
|
||||
for (std::size_t i = 0; i < indexes.size(); ++i) {
|
||||
if (indexes[i] >= arrayInfo.num(i)) {
|
||||
if (indexes.size() == 1U) {
|
||||
arrayIndexOutOfBoundsError(tok->tokAt(1 + varcount), arrayInfo, indexes);
|
||||
|
@ -752,8 +752,8 @@ void CheckBufferOverrun::valueFlowCheckArrayIndex(const Token * const tok, const
|
|||
MathLib::bigint totalIndex = 0;
|
||||
|
||||
// calculate the totalElements and totalIndex..
|
||||
for (unsigned int i = 0; i < indexes.size(); ++i) {
|
||||
std::size_t ri = indexes.size() - 1 - i;
|
||||
for (std::size_t i = 0; i < indexes.size(); ++i) {
|
||||
const std::size_t ri = indexes.size() - 1 - i;
|
||||
totalIndex += indexes[ri].intvalue * totalElements;
|
||||
totalElements *= arrayInfo.num(ri);
|
||||
}
|
||||
|
@ -775,7 +775,7 @@ void CheckBufferOverrun::valueFlowCheckArrayIndex(const Token * const tok, const
|
|||
// Is any array index out of bounds?
|
||||
else {
|
||||
// check each index for overflow
|
||||
for (unsigned int i = 0; i < indexes.size(); ++i) {
|
||||
for (std::size_t i = 0; i < indexes.size(); ++i) {
|
||||
if (indexes[i].intvalue >= arrayInfo.num(i)) {
|
||||
// The access is still within the memory range for the array
|
||||
// so it may be intentional.
|
||||
|
@ -1399,7 +1399,7 @@ MathLib::bigint CheckBufferOverrun::countSprintfLength(const std::string &input_
|
|||
|
||||
if (digits_string.find('.') != std::string::npos) {
|
||||
const std::string endStr = digits_string.substr(digits_string.find('.') + 1);
|
||||
unsigned int maxLen = std::max(static_cast<unsigned int>(std::abs(std::atoi(endStr.c_str()))), 1U);
|
||||
const unsigned int maxLen = std::max(static_cast<unsigned int>(std::abs(std::atoi(endStr.c_str()))), 1U);
|
||||
|
||||
if (input_string[i] == 's') {
|
||||
// For strings, the length after the dot "%.2s" will limit
|
||||
|
|
|
@ -1422,7 +1422,7 @@ void CheckClass::virtualDestructor()
|
|||
const Token *derivedClass = derived->next();
|
||||
|
||||
// Iterate through each base class...
|
||||
for (unsigned int j = 0; j < scope->definedType->derivedFrom.size(); ++j) {
|
||||
for (std::size_t j = 0; j < scope->definedType->derivedFrom.size(); ++j) {
|
||||
// Check if base class is public and exists in database
|
||||
if (scope->definedType->derivedFrom[j].access != Private && scope->definedType->derivedFrom[j].type) {
|
||||
const Type *derivedFrom = scope->definedType->derivedFrom[j].type;
|
||||
|
@ -1680,7 +1680,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
|
|||
// not found in this class
|
||||
if (!scope->definedType->derivedFrom.empty() && !scope->definedType->hasCircularDependencies()) {
|
||||
// check each base class
|
||||
for (unsigned int i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
|
||||
for (std::size_t i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
|
||||
// find the base class
|
||||
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
|
||||
|
||||
|
@ -1746,7 +1746,7 @@ bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const
|
|||
// not found in this class
|
||||
if (!scope->definedType->derivedFrom.empty()) {
|
||||
// check each base class
|
||||
for (unsigned int i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
|
||||
for (std::size_t i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
|
||||
// find the base class
|
||||
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
|
||||
|
||||
|
@ -1786,7 +1786,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
|
|||
// not found in this class
|
||||
if (!scope->definedType->derivedFrom.empty()) {
|
||||
// check each base class
|
||||
for (unsigned int i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
|
||||
for (std::size_t i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
|
||||
// find the base class
|
||||
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
|
||||
|
||||
|
|
|
@ -363,7 +363,7 @@ void CheckIO::invalidScanf()
|
|||
|
||||
// scan the string backwards, so we do not need to keep states
|
||||
const std::string &formatstr(formatToken->str());
|
||||
for (unsigned int i = 1; i < formatstr.length(); i++) {
|
||||
for (std::size_t i = 1; i < formatstr.length(); i++) {
|
||||
if (formatstr[i] == '%')
|
||||
format = !format;
|
||||
|
||||
|
|
|
@ -871,7 +871,7 @@ std::string Preprocessor::removeSpaceNearNL(const std::string &str)
|
|||
{
|
||||
std::string tmp;
|
||||
char prev = 0;
|
||||
for (unsigned int i = 0; i < str.size(); i++) {
|
||||
for (std::size_t i = 0; i < str.size(); i++) {
|
||||
if (str[i] == ' ' &&
|
||||
((i > 0 && prev == '\n') ||
|
||||
(i + 1 < str.size() && str[i+1] == '\n')
|
||||
|
@ -2569,7 +2569,7 @@ private:
|
|||
|
||||
std::vector<std::string> params2(params1);
|
||||
|
||||
for (unsigned int ipar = 0; ipar < params1.size(); ++ipar) {
|
||||
for (std::size_t ipar = 0; ipar < params1.size(); ++ipar) {
|
||||
const std::string s(innerMacroName + "(");
|
||||
std::string param(params1[ipar]);
|
||||
if (param.compare(0,s.length(),s)==0 && param[param.length()-1]==')') {
|
||||
|
@ -2695,7 +2695,7 @@ public:
|
|||
// Replace "__VA_ARGS__" with parameters
|
||||
if (!_nopar) {
|
||||
std::string s;
|
||||
for (unsigned int i = 0; i < params2.size(); ++i) {
|
||||
for (std::size_t i = 0; i < params2.size(); ++i) {
|
||||
if (i > 0)
|
||||
s += ",";
|
||||
s += params2[i];
|
||||
|
@ -2740,13 +2740,13 @@ public:
|
|||
if (stringify) {
|
||||
str = str.erase(0, 1);
|
||||
}
|
||||
for (unsigned int i = 0; i < _params.size(); ++i) {
|
||||
for (std::size_t i = 0; i < _params.size(); ++i) {
|
||||
if (str == _params[i]) {
|
||||
if (_variadic &&
|
||||
(i == _params.size() - 1 ||
|
||||
(givenparams.size() + 2 == _params.size() && i + 1 == _params.size() - 1))) {
|
||||
str = "";
|
||||
for (unsigned int j = (unsigned int)_params.size() - 1; j < givenparams.size(); ++j) {
|
||||
for (std::size_t j = _params.size() - 1; j < givenparams.size(); ++j) {
|
||||
if (optcomma || j > _params.size() - 1)
|
||||
str += ",";
|
||||
optcomma = false;
|
||||
|
|
|
@ -51,7 +51,7 @@ static void printlist(const std::list<Token *> &list)
|
|||
|
||||
static void printvector(const std::vector<const Token *> &v)
|
||||
{
|
||||
for (unsigned int i = 0; i < v.size(); i++) {
|
||||
for (std::size_t i = 0; i < v.size(); i++) {
|
||||
const Token *token = v[i];
|
||||
std::cout << " " << i << ":";
|
||||
while (token && !Token::Match(token, "[{};]")) {
|
||||
|
|
|
@ -75,7 +75,7 @@ void TokenList::deallocateTokens()
|
|||
unsigned int TokenList::appendFileIfNew(const std::string &fileName)
|
||||
{
|
||||
// Has this file been tokenized already?
|
||||
for (unsigned int i = 0; i < _files.size(); ++i)
|
||||
for (std::size_t i = 0; i < _files.size(); ++i)
|
||||
if (Path::sameFileName(_files[i], fileName))
|
||||
return i;
|
||||
|
||||
|
@ -391,7 +391,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
|
|||
_back->isExpandedMacro(expandedMacro);
|
||||
Token::assignProgressValues(_front);
|
||||
|
||||
for (unsigned int i = 1; i < _files.size(); i++)
|
||||
for (std::size_t i = 1; i < _files.size(); i++)
|
||||
_files[i] = Path::getRelativePath(_files[i], _settings->_basePaths);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -1337,7 +1337,7 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg
|
|||
}
|
||||
|
||||
std::map<unsigned int, MathLib::bigint> programMemory;
|
||||
for (unsigned int i = 0; i < parvalues.size(); ++i) {
|
||||
for (std::size_t i = 0; i < parvalues.size(); ++i) {
|
||||
const Variable * const arg = function->getArgumentVar(i);
|
||||
if (!arg || !Token::Match(arg->typeStartToken(), "%type% %var% ,|)")) {
|
||||
if (settings->debugwarnings)
|
||||
|
|
Loading…
Reference in New Issue