From f5e76a2d1870812c269d161ebe1f0bda990476bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 13 Jul 2019 15:31:17 +0200 Subject: [PATCH] Avoid 'unsigned' when declaring int variables in checkuninitvar --- lib/checkuninitvar.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 0d09286a9..c68c1a65c 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -149,13 +149,13 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set if (var.isArray()) { Alloc alloc = ARRAY; - const std::map variableValue; + const std::map variableValue; checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue); continue; } if (stdtype || var.isPointer()) { Alloc alloc = NO_ALLOC; - const std::map variableValue; + const std::map variableValue; checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue); } if (var.type()) @@ -173,7 +173,7 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set checkStruct(tok, arg); else if (arg.typeStartToken()->isStandardType() || arg.typeStartToken()->isEnumType()) { Alloc alloc = NO_ALLOC; - const std::map variableValue; + const std::map variableValue; checkScopeForVariable(tok->next(), arg, nullptr, nullptr, &alloc, emptyString, variableValue); } } @@ -211,7 +211,7 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar) const Token *tok2 = tok; if (tok->str() == "}") tok2 = tok2->next(); - const std::map variableValue; + const std::map variableValue; checkScopeForVariable(tok2, structvar, nullptr, nullptr, &alloc, var.name(), variableValue); } } @@ -233,7 +233,7 @@ static bool operator!=(const VariableValue & v, MathLib::bigint i) return v.notEqual ? (i == v.value) : (i != v.value); } -static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map &variableValue, bool *alwaysTrue, bool *alwaysFalse) +static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map &variableValue, bool *alwaysTrue, bool *alwaysFalse) { if (!tok) return; @@ -241,7 +241,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::mapisName() || tok->str() == ".") { while (tok && tok->str() == ".") tok = tok->astOperand2(); - const std::map::const_iterator it = variableValue.find(tok ? tok->varId() : ~0U); + const std::map::const_iterator it = variableValue.find(tok ? tok->varId() : ~0U); if (it != variableValue.end()) { *alwaysTrue = (it->second != 0LL); *alwaysFalse = (it->second == 0LL); @@ -271,7 +271,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::mapstr() == ".") vartok = vartok->astOperand2(); - const std::map::const_iterator it = variableValue.find(vartok ? vartok->varId() : ~0U); + const std::map::const_iterator it = variableValue.find(vartok ? vartok->varId() : ~0U); if (it == variableValue.end()) return; @@ -338,7 +338,7 @@ static bool isVariableUsed(const Token *tok, const Variable& var) return !parent2 || parent2->isConstOp() || (parent2->str() == "=" && parent2->astOperand2() == parent); } -bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn, Alloc* const alloc, const std::string &membervar, std::map variableValue) +bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn, Alloc* const alloc, const std::string &membervar, std::map variableValue) { const bool suppressErrors(possibleInit && *possibleInit); // Assume that this is a variable delaratkon, rather than a fundef const bool printDebug = mSettings->debugwarnings; @@ -346,7 +346,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var if (possibleInit) *possibleInit = false; - unsigned int number_of_if = 0; + int number_of_if = 0; if (var.declarationId() == 0U) return true; @@ -399,14 +399,14 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var return true; // checking if a not-zero variable is zero => bail out - unsigned int condVarId = 0; + int condVarId = 0; VariableValue condVarValue(0); const Token *condVarTok = nullptr; if (alwaysFalse) ; else if (Token::simpleMatch(tok, "if (") && astIsVariableComparison(tok->next()->astOperand2(), "!=", "0", &condVarTok)) { - const std::map::const_iterator it = variableValue.find(condVarTok->varId()); + const std::map::const_iterator it = variableValue.find(condVarTok->varId()); if (it != variableValue.end() && it->second != 0) return true; // this scope is not fully analysed => return true else { @@ -422,7 +422,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var while (Token::simpleMatch(vartok, ".")) vartok = vartok->astOperand2(); if (vartok && vartok->varId() && numtok) { - const std::map::const_iterator it = variableValue.find(vartok->varId()); + const std::map::const_iterator it = variableValue.find(vartok->varId()); if (it != variableValue.end() && it->second != MathLib::toLongNumber(numtok->str())) return true; // this scope is not fully analysed => return true else { @@ -464,7 +464,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var if (alwaysTrue && (initif || noreturnIf)) return true; - std::map varValueIf; + std::map varValueIf; if (!alwaysFalse && !initif && !noreturnIf) { for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) { if (Token::Match(tok2, "[;{}.] %name% = - %name% ;")) @@ -494,7 +494,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var bool noreturnElse = false; const bool initelse = !alwaysTrue && checkScopeForVariable(tok->next(), var, &possibleInitElse, &noreturnElse, alloc, membervar, variableValue); - std::map varValueElse; + std::map varValueElse; if (!alwaysTrue && !initelse && !noreturnElse) { for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) { if (Token::Match(tok2, "[;{}.] %var% = - %name% ;")) @@ -879,10 +879,10 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const return false; } -void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, Alloc alloc, unsigned int number_of_if, const std::string &membervar) +void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, Alloc alloc, int number_of_if, const std::string &membervar) { bool rhs = false; - unsigned int indent = 0; + int indent = 0; while (nullptr != (tok = tok->next())) { if (tok->str() == "=") rhs = true; @@ -1083,7 +1083,7 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc return -1; // locate start parentheses in function call.. - unsigned int argumentNumber = 0; + int argumentNumber = 0; const Token *start = vartok; while (start && !Token::Match(start, "[;{}(]")) { if (start->str() == ")") @@ -1172,7 +1172,7 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str } else if (tok->strAt(-1) == "&") { if (Token::Match(tok->tokAt(-2), "[(,] & %name%")) { // locate start parentheses in function call.. - unsigned int argumentNumber = 0; + int argumentNumber = 0; const Token *ftok = tok; while (ftok && !Token::Match(ftok, "[;{}(]")) { if (ftok->str() == ")")