Avoid 'unsigned' when declaring int variables in checkuninitvar
This commit is contained in:
parent
794d25fcf5
commit
f5e76a2d18
|
@ -149,13 +149,13 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string>
|
||||||
|
|
||||||
if (var.isArray()) {
|
if (var.isArray()) {
|
||||||
Alloc alloc = ARRAY;
|
Alloc alloc = ARRAY;
|
||||||
const std::map<unsigned int, VariableValue> variableValue;
|
const std::map<int, VariableValue> variableValue;
|
||||||
checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue);
|
checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (stdtype || var.isPointer()) {
|
if (stdtype || var.isPointer()) {
|
||||||
Alloc alloc = NO_ALLOC;
|
Alloc alloc = NO_ALLOC;
|
||||||
const std::map<unsigned int, VariableValue> variableValue;
|
const std::map<int, VariableValue> variableValue;
|
||||||
checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue);
|
checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue);
|
||||||
}
|
}
|
||||||
if (var.type())
|
if (var.type())
|
||||||
|
@ -173,7 +173,7 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string>
|
||||||
checkStruct(tok, arg);
|
checkStruct(tok, arg);
|
||||||
else if (arg.typeStartToken()->isStandardType() || arg.typeStartToken()->isEnumType()) {
|
else if (arg.typeStartToken()->isStandardType() || arg.typeStartToken()->isEnumType()) {
|
||||||
Alloc alloc = NO_ALLOC;
|
Alloc alloc = NO_ALLOC;
|
||||||
const std::map<unsigned int, VariableValue> variableValue;
|
const std::map<int, VariableValue> variableValue;
|
||||||
checkScopeForVariable(tok->next(), arg, nullptr, nullptr, &alloc, emptyString, 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;
|
const Token *tok2 = tok;
|
||||||
if (tok->str() == "}")
|
if (tok->str() == "}")
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
const std::map<unsigned int, VariableValue> variableValue;
|
const std::map<int, VariableValue> variableValue;
|
||||||
checkScopeForVariable(tok2, structvar, nullptr, nullptr, &alloc, var.name(), 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);
|
return v.notEqual ? (i == v.value) : (i != v.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<unsigned int, VariableValue> &variableValue, bool *alwaysTrue, bool *alwaysFalse)
|
static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<int, VariableValue> &variableValue, bool *alwaysTrue, bool *alwaysFalse)
|
||||||
{
|
{
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return;
|
return;
|
||||||
|
@ -241,7 +241,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<unsigned
|
||||||
if (tok->isName() || tok->str() == ".") {
|
if (tok->isName() || tok->str() == ".") {
|
||||||
while (tok && tok->str() == ".")
|
while (tok && tok->str() == ".")
|
||||||
tok = tok->astOperand2();
|
tok = tok->astOperand2();
|
||||||
const std::map<unsigned int, VariableValue>::const_iterator it = variableValue.find(tok ? tok->varId() : ~0U);
|
const std::map<int, VariableValue>::const_iterator it = variableValue.find(tok ? tok->varId() : ~0U);
|
||||||
if (it != variableValue.end()) {
|
if (it != variableValue.end()) {
|
||||||
*alwaysTrue = (it->second != 0LL);
|
*alwaysTrue = (it->second != 0LL);
|
||||||
*alwaysFalse = (it->second == 0LL);
|
*alwaysFalse = (it->second == 0LL);
|
||||||
|
@ -271,7 +271,7 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<unsigned
|
||||||
while (vartok && vartok->str() == ".")
|
while (vartok && vartok->str() == ".")
|
||||||
vartok = vartok->astOperand2();
|
vartok = vartok->astOperand2();
|
||||||
|
|
||||||
const std::map<unsigned int, VariableValue>::const_iterator it = variableValue.find(vartok ? vartok->varId() : ~0U);
|
const std::map<int, VariableValue>::const_iterator it = variableValue.find(vartok ? vartok->varId() : ~0U);
|
||||||
if (it == variableValue.end())
|
if (it == variableValue.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ static bool isVariableUsed(const Token *tok, const Variable& var)
|
||||||
return !parent2 || parent2->isConstOp() || (parent2->str() == "=" && parent2->astOperand2() == parent);
|
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<unsigned int, VariableValue> 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<int, VariableValue> variableValue)
|
||||||
{
|
{
|
||||||
const bool suppressErrors(possibleInit && *possibleInit); // Assume that this is a variable delaratkon, rather than a fundef
|
const bool suppressErrors(possibleInit && *possibleInit); // Assume that this is a variable delaratkon, rather than a fundef
|
||||||
const bool printDebug = mSettings->debugwarnings;
|
const bool printDebug = mSettings->debugwarnings;
|
||||||
|
@ -346,7 +346,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
if (possibleInit)
|
if (possibleInit)
|
||||||
*possibleInit = false;
|
*possibleInit = false;
|
||||||
|
|
||||||
unsigned int number_of_if = 0;
|
int number_of_if = 0;
|
||||||
|
|
||||||
if (var.declarationId() == 0U)
|
if (var.declarationId() == 0U)
|
||||||
return true;
|
return true;
|
||||||
|
@ -399,14 +399,14 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// checking if a not-zero variable is zero => bail out
|
// checking if a not-zero variable is zero => bail out
|
||||||
unsigned int condVarId = 0;
|
int condVarId = 0;
|
||||||
VariableValue condVarValue(0);
|
VariableValue condVarValue(0);
|
||||||
const Token *condVarTok = nullptr;
|
const Token *condVarTok = nullptr;
|
||||||
if (alwaysFalse)
|
if (alwaysFalse)
|
||||||
;
|
;
|
||||||
else if (Token::simpleMatch(tok, "if (") &&
|
else if (Token::simpleMatch(tok, "if (") &&
|
||||||
astIsVariableComparison(tok->next()->astOperand2(), "!=", "0", &condVarTok)) {
|
astIsVariableComparison(tok->next()->astOperand2(), "!=", "0", &condVarTok)) {
|
||||||
const std::map<unsigned int,VariableValue>::const_iterator it = variableValue.find(condVarTok->varId());
|
const std::map<int,VariableValue>::const_iterator it = variableValue.find(condVarTok->varId());
|
||||||
if (it != variableValue.end() && it->second != 0)
|
if (it != variableValue.end() && it->second != 0)
|
||||||
return true; // this scope is not fully analysed => return true
|
return true; // this scope is not fully analysed => return true
|
||||||
else {
|
else {
|
||||||
|
@ -422,7 +422,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
while (Token::simpleMatch(vartok, "."))
|
while (Token::simpleMatch(vartok, "."))
|
||||||
vartok = vartok->astOperand2();
|
vartok = vartok->astOperand2();
|
||||||
if (vartok && vartok->varId() && numtok) {
|
if (vartok && vartok->varId() && numtok) {
|
||||||
const std::map<unsigned int,VariableValue>::const_iterator it = variableValue.find(vartok->varId());
|
const std::map<int,VariableValue>::const_iterator it = variableValue.find(vartok->varId());
|
||||||
if (it != variableValue.end() && it->second != MathLib::toLongNumber(numtok->str()))
|
if (it != variableValue.end() && it->second != MathLib::toLongNumber(numtok->str()))
|
||||||
return true; // this scope is not fully analysed => return true
|
return true; // this scope is not fully analysed => return true
|
||||||
else {
|
else {
|
||||||
|
@ -464,7 +464,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
if (alwaysTrue && (initif || noreturnIf))
|
if (alwaysTrue && (initif || noreturnIf))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
std::map<unsigned int, VariableValue> varValueIf;
|
std::map<int, VariableValue> varValueIf;
|
||||||
if (!alwaysFalse && !initif && !noreturnIf) {
|
if (!alwaysFalse && !initif && !noreturnIf) {
|
||||||
for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) {
|
for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) {
|
||||||
if (Token::Match(tok2, "[;{}.] %name% = - %name% ;"))
|
if (Token::Match(tok2, "[;{}.] %name% = - %name% ;"))
|
||||||
|
@ -494,7 +494,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
bool noreturnElse = false;
|
bool noreturnElse = false;
|
||||||
const bool initelse = !alwaysTrue && checkScopeForVariable(tok->next(), var, &possibleInitElse, &noreturnElse, alloc, membervar, variableValue);
|
const bool initelse = !alwaysTrue && checkScopeForVariable(tok->next(), var, &possibleInitElse, &noreturnElse, alloc, membervar, variableValue);
|
||||||
|
|
||||||
std::map<unsigned int, VariableValue> varValueElse;
|
std::map<int, VariableValue> varValueElse;
|
||||||
if (!alwaysTrue && !initelse && !noreturnElse) {
|
if (!alwaysTrue && !initelse && !noreturnElse) {
|
||||||
for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) {
|
for (const Token *tok2 = tok; tok2 && tok2 != tok->link(); tok2 = tok2->next()) {
|
||||||
if (Token::Match(tok2, "[;{}.] %var% = - %name% ;"))
|
if (Token::Match(tok2, "[;{}.] %var% = - %name% ;"))
|
||||||
|
@ -879,10 +879,10 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
|
||||||
return false;
|
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;
|
bool rhs = false;
|
||||||
unsigned int indent = 0;
|
int indent = 0;
|
||||||
while (nullptr != (tok = tok->next())) {
|
while (nullptr != (tok = tok->next())) {
|
||||||
if (tok->str() == "=")
|
if (tok->str() == "=")
|
||||||
rhs = true;
|
rhs = true;
|
||||||
|
@ -1083,7 +1083,7 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// locate start parentheses in function call..
|
// locate start parentheses in function call..
|
||||||
unsigned int argumentNumber = 0;
|
int argumentNumber = 0;
|
||||||
const Token *start = vartok;
|
const Token *start = vartok;
|
||||||
while (start && !Token::Match(start, "[;{}(]")) {
|
while (start && !Token::Match(start, "[;{}(]")) {
|
||||||
if (start->str() == ")")
|
if (start->str() == ")")
|
||||||
|
@ -1172,7 +1172,7 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
|
||||||
} else if (tok->strAt(-1) == "&") {
|
} else if (tok->strAt(-1) == "&") {
|
||||||
if (Token::Match(tok->tokAt(-2), "[(,] & %name%")) {
|
if (Token::Match(tok->tokAt(-2), "[(,] & %name%")) {
|
||||||
// locate start parentheses in function call..
|
// locate start parentheses in function call..
|
||||||
unsigned int argumentNumber = 0;
|
int argumentNumber = 0;
|
||||||
const Token *ftok = tok;
|
const Token *ftok = tok;
|
||||||
while (ftok && !Token::Match(ftok, "[;{}(]")) {
|
while (ftok && !Token::Match(ftok, "[;{}(]")) {
|
||||||
if (ftok->str() == ")")
|
if (ftok->str() == ")")
|
||||||
|
|
Loading…
Reference in New Issue