Fixed GCC compiler warnings
This commit is contained in:
parent
4e07a13feb
commit
98c7c0af96
|
@ -344,23 +344,18 @@ static bool isComputableValue(const Token* parent, const ValueFlow::Value& value
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T asInt(T x)
|
static bool isEqual(T x, T y) {
|
||||||
{
|
T diff = (x > y) ? x - y : y - x;
|
||||||
return x;
|
return !((diff / 2) < diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
MathLib::bigint asInt(float x)
|
template<class T>
|
||||||
{
|
static bool isZero(T x) {
|
||||||
return x;
|
return isEqual<T>(x, T(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
MathLib::bigint asInt(double x)
|
template <class T>
|
||||||
{
|
static T calculate(const std::string& s, T x, T y)
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T, class U>
|
|
||||||
static T calculate(const std::string& s, T x, U y)
|
|
||||||
{
|
{
|
||||||
switch (MathLib::encodeMultiChar(s)) {
|
switch (MathLib::encodeMultiChar(s)) {
|
||||||
case '+':
|
case '+':
|
||||||
|
@ -372,29 +367,29 @@ static T calculate(const std::string& s, T x, U y)
|
||||||
case '/':
|
case '/':
|
||||||
return x / y;
|
return x / y;
|
||||||
case '%':
|
case '%':
|
||||||
return asInt(x) % asInt(y);
|
return MathLib::bigint(x) % MathLib::bigint(y);
|
||||||
case '&':
|
case '&':
|
||||||
return asInt(x) & asInt(y);
|
return MathLib::bigint(x) & MathLib::bigint(y);
|
||||||
case '|':
|
case '|':
|
||||||
return asInt(x) | asInt(y);
|
return MathLib::bigint(x) | MathLib::bigint(y);
|
||||||
case '^':
|
case '^':
|
||||||
return asInt(x) ^ asInt(y);
|
return MathLib::bigint(x) ^ MathLib::bigint(y);
|
||||||
case '>':
|
case '>':
|
||||||
return x > y;
|
return x > y;
|
||||||
case '<':
|
case '<':
|
||||||
return x < y;
|
return x < y;
|
||||||
case '<<':
|
case '<<':
|
||||||
return asInt(x) << asInt(y);
|
return MathLib::bigint(x) << MathLib::bigint(y);
|
||||||
case '>>':
|
case '>>':
|
||||||
return asInt(x) >> asInt(y);
|
return MathLib::bigint(x) >> MathLib::bigint(y);
|
||||||
case '&&':
|
case '&&':
|
||||||
return x && y;
|
return !isZero(x) && !isZero(y);
|
||||||
case '||':
|
case '||':
|
||||||
return x || y;
|
return !isZero(x) || !isZero(y);
|
||||||
case '==':
|
case '==':
|
||||||
return x == y;
|
return isEqual(x, y);
|
||||||
case '!=':
|
case '!=':
|
||||||
return x != y;
|
return !isEqual(x, y);
|
||||||
case '>=':
|
case '>=':
|
||||||
return x >= y;
|
return x >= y;
|
||||||
case '<=':
|
case '<=':
|
||||||
|
@ -435,9 +430,9 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
if (value1.isContainerSizeValue() && value2.isContainerSizeValue())
|
if (value1.isContainerSizeValue() && value2.isContainerSizeValue())
|
||||||
result.intvalue = calculate(parent->str(), value1.intvalue, value2.intvalue);
|
result.intvalue = calculate(parent->str(), value1.intvalue, value2.intvalue);
|
||||||
else if (value1.isContainerSizeValue() && value2.isTokValue() && value2.tokvalue->tokType() == Token::eString)
|
else if (value1.isContainerSizeValue() && value2.isTokValue() && value2.tokvalue->tokType() == Token::eString)
|
||||||
result.intvalue = calculate(parent->str(), value1.intvalue, Token::getStrLength(value2.tokvalue));
|
result.intvalue = calculate(parent->str(), value1.intvalue, MathLib::bigint(Token::getStrLength(value2.tokvalue)));
|
||||||
else if (value2.isContainerSizeValue() && value1.isTokValue() && value1.tokvalue->tokType() == Token::eString)
|
else if (value2.isContainerSizeValue() && value1.isTokValue() && value1.tokvalue->tokType() == Token::eString)
|
||||||
result.intvalue = calculate(parent->str(), Token::getStrLength(value1.tokvalue), value2.intvalue);
|
result.intvalue = calculate(parent->str(), MathLib::bigint(Token::getStrLength(value1.tokvalue)), value2.intvalue);
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -622,7 +617,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
|
||||||
if (Token::Match(parent, "<<|>>") &&
|
if (Token::Match(parent, "<<|>>") &&
|
||||||
!(value1.intvalue >= 0 && value2.intvalue >= 0 && value2.intvalue < MathLib::bigint_bits))
|
!(value1.intvalue >= 0 && value2.intvalue >= 0 && value2.intvalue < MathLib::bigint_bits))
|
||||||
continue;
|
continue;
|
||||||
if (Token::Match(parent, "/|%") && floatValue2 == 0)
|
if (Token::Match(parent, "/|%") && isZero<double>(floatValue2))
|
||||||
continue;
|
continue;
|
||||||
if (Token::Match(parent, "==|!=")) {
|
if (Token::Match(parent, "==|!=")) {
|
||||||
if ((value1.isIntValue() && value2.isTokValue()) || (value1.isTokValue() && value2.isIntValue())) {
|
if ((value1.isIntValue() && value2.isTokValue()) || (value1.isTokValue() && value2.isIntValue())) {
|
||||||
|
@ -5585,28 +5580,6 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hasContainerSizeGuard(const Token *tok, nonneg int containerId)
|
|
||||||
{
|
|
||||||
for (; tok && tok->astParent(); tok = tok->astParent()) {
|
|
||||||
const Token *parent = tok->astParent();
|
|
||||||
if (tok != parent->astOperand2())
|
|
||||||
continue;
|
|
||||||
if (!Token::Match(parent, "%oror%|&&|?"))
|
|
||||||
continue;
|
|
||||||
// is container found in lhs?
|
|
||||||
bool found = false;
|
|
||||||
visitAstNodes(parent->astOperand1(),
|
|
||||||
[&](const Token *t) {
|
|
||||||
if (t->varId() == containerId)
|
|
||||||
found = true;
|
|
||||||
return found ? ChildrenToVisit::done : ChildrenToVisit::op1_and_op2;
|
|
||||||
});
|
|
||||||
if (found)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isContainerSize(const Token* tok)
|
static bool isContainerSize(const Token* tok)
|
||||||
{
|
{
|
||||||
if (!Token::Match(tok, "%var% . %name% ("))
|
if (!Token::Match(tok, "%var% . %name% ("))
|
||||||
|
|
Loading…
Reference in New Issue