Skip to content

Commit 047b725

Browse files
authored
explicitly convert MathLib::big{u}int to/from other types / small cleanup (danmar#7129)
fixes some compiler warnings with `USE_BOOST_INT128` as those implicit conversions are not allowed
1 parent 8576ec9 commit 047b725

File tree

12 files changed

+66
-111
lines changed

12 files changed

+66
-111
lines changed

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4056,7 +4056,7 @@ void CheckOther::knownPointerToBoolError(const Token* tok, const ValueFlow::Valu
40564056
reportError(tok, Severity::style, "knownPointerToBool", "Pointer expression 'p' converted to bool is always true.");
40574057
return;
40584058
}
4059-
std::string cond = bool_to_string(value->intvalue);
4059+
std::string cond = bool_to_string(!!value->intvalue);
40604060
const std::string& expr = tok->expressionString();
40614061
std::string errmsg = "Pointer expression '" + expr + "' converted to bool is always " + cond + ".";
40624062
const ErrorPath errorPath = getErrorPath(tok, value, errmsg);

lib/fwdanalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
224224
const Token *conditionStart = tok->next();
225225
const Token *condTok = conditionStart->astOperand2();
226226
if (condTok->hasKnownIntValue()) {
227-
const bool cond = condTok->values().front().intvalue;
227+
const bool cond = !!condTok->values().front().intvalue;
228228
if (cond) {
229229
FwdAnalysis::Result result = checkRecursive(expr, bodyStart, bodyStart->link(), exprVarIds, local, true, depth);
230230
if (result.type != Result::Type::NONE)

lib/infer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ std::vector<ValueFlow::Value> infer(const ValuePtr<InferModel>& model,
349349
std::vector<const ValueFlow::Value*> refs;
350350
std::vector<bool> r = Interval::compare(op, lhs, rhs, &refs);
351351
if (!r.empty()) {
352-
ValueFlow::Value value(r.front());
352+
ValueFlow::Value value(static_cast<int>(r.front()));
353353
addToErrorPath(value, refs);
354354
setValueKind(value, refs);
355355
result.push_back(std::move(value));

lib/library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ bool Library::isIntArgValid(const Token *ftok, int argnr, const MathLib::bigint
10551055
if (!ac || ac->valid.empty())
10561056
return true;
10571057
if (ac->valid.find('.') != std::string::npos)
1058-
return isFloatArgValid(ftok, argnr, argvalue);
1058+
return isFloatArgValid(ftok, argnr, static_cast<double>(argvalue));
10591059
TokenList tokenList(nullptr);
10601060
gettokenlistfromvalid(ac->valid, ftok->isCpp(), tokenList);
10611061
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {

lib/mathlib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void MathLib::value::promote(const MathLib::value &v)
116116
}
117117
} else if (!isFloat()) {
118118
mIsUnsigned = false;
119-
mDoubleValue = mIntValue;
119+
mDoubleValue = static_cast<double>(mIntValue);
120120
mType = MathLib::value::Type::FLOAT;
121121
}
122122
}

lib/pathanalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ std::pair<bool, bool> PathAnalysis::checkCond(const Token * tok, bool& known)
5050
{
5151
if (tok->hasKnownIntValue()) {
5252
known = true;
53-
return std::make_pair(tok->values().front().intvalue, !tok->values().front().intvalue);
53+
return std::make_pair(!!tok->values().front().intvalue, !tok->values().front().intvalue);
5454
}
5555
auto it = std::find_if(tok->values().cbegin(), tok->values().cend(), [](const ValueFlow::Value& v) {
5656
return v.isIntValue();
@@ -62,7 +62,7 @@ std::pair<bool, bool> PathAnalysis::checkCond(const Token * tok, bool& known)
6262
return true;
6363
})) {
6464
known = false;
65-
return std::make_pair(it->intvalue, !it->intvalue);
65+
return std::make_pair(!!it->intvalue, !it->intvalue);
6666
}
6767
return std::make_pair(true, true);
6868
}

lib/programmemory.cpp

Lines changed: 47 additions & 92 deletions
Large diffs are not rendered by default.

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9894,7 +9894,7 @@ void Tokenizer::simplifyBitfields()
98949894
!Token::simpleMatch(tok->tokAt(2), "default :")) {
98959895
Token *tok1 = (tok->strAt(1) == "const") ? tok->tokAt(3) : tok->tokAt(2);
98969896
if (Token::Match(tok1, "%name% : %num% [;=]"))
9897-
tok1->setBits(MathLib::toBigNumber(tok1->strAt(2)));
9897+
tok1->setBits(static_cast<unsigned char>(MathLib::toBigNumber(tok1->strAt(2))));
98989898
if (tok1 && tok1->tokAt(2) &&
98999899
(Token::Match(tok1->tokAt(2), "%bool%|%num%") ||
99009900
!Token::Match(tok1->tokAt(2), "public|protected|private| %type% ::|<|,|{|;"))) {

lib/valueflow.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,14 +759,14 @@ static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings
759759
result.intvalue = 0;
760760
setTokenValue(tok, std::move(result), settings);
761761
} else if (index >= 0 && index < s.size()) {
762-
result.intvalue = s[index];
762+
result.intvalue = s[static_cast<std::size_t>(index)];
763763
setTokenValue(tok, std::move(result), settings);
764764
}
765765
} else if (Token::simpleMatch(arrayValue.tokvalue, "{")) {
766766
std::vector<const Token*> args = getArguments(arrayValue.tokvalue);
767767
if (index < 0 || index >= args.size())
768768
continue;
769-
const Token* arg = args[index];
769+
const Token* arg = args[static_cast<std::size_t>(index)];
770770
if (!arg->hasKnownIntValue())
771771
continue;
772772
const ValueFlow::Value& v = arg->values().front();
@@ -3982,7 +3982,7 @@ static std::list<ValueFlow::Value> truncateValues(std::list<ValueFlow::Value> va
39823982
if (value.isImpossible())
39833983
continue;
39843984
if (value.isFloatValue()) {
3985-
value.intvalue = value.floatValue;
3985+
value.intvalue = static_cast<MathLib::bigint>(value.floatValue);
39863986
value.valueType = ValueFlow::Value::ValueType::INT;
39873987
}
39883988

@@ -4505,7 +4505,7 @@ struct ConditionHandler {
45054505
if (Token::Match(tok->astParent(), "==|!=")) {
45064506
const Token* sibling = tok->astSibling();
45074507
if (sibling->hasKnownIntValue() && (astIsBool(tok) || astIsBool(sibling))) {
4508-
const bool value = sibling->values().front().intvalue;
4508+
const bool value = !!sibling->values().front().intvalue;
45094509
if (inverted)
45104510
*inverted ^= value == Token::simpleMatch(tok->astParent(), "!=");
45114511
continue;
@@ -6916,12 +6916,12 @@ static void valueFlowSafeFunctions(const TokenList& tokenlist, const SymbolDatab
69166916
std::list<ValueFlow::Value> argValues;
69176917
argValues.emplace_back(0);
69186918
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
6919-
argValues.back().floatValue = isLow ? low : -1E25;
6919+
argValues.back().floatValue = isLow ? static_cast<double>(low) : -1E25;
69206920
argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue));
69216921
argValues.back().safe = true;
69226922
argValues.emplace_back(0);
69236923
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
6924-
argValues.back().floatValue = isHigh ? high : 1E25;
6924+
argValues.back().floatValue = isHigh ? static_cast<double>(high) : 1E25;
69256925
argValues.back().errorPath.emplace_back(arg.nameToken(), "Safe checks: Assuming argument has value " + MathLib::toString(argValues.back().floatValue));
69266926
argValues.back().safe = true;
69276927
valueFlowForward(const_cast<Token*>(functionScope->bodyStart->next()),

lib/vf_analyzers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ struct ValueFlowAnalyzer : Analyzer {
470470
return T{};
471471
}
472472
if (assign == "=")
473-
return y;
473+
return static_cast<T>(y);
474474
return calculate<T, T>(removeAssign(assign), x, y, error);
475475
}
476476

0 commit comments

Comments
 (0)