Skip to content

Commit 275a2e2

Browse files
committed
resolve -Wconversion warnings / typing, avoid implicit modifying casts
1 parent eee1a1e commit 275a2e2

File tree

10 files changed

+117
-115
lines changed

10 files changed

+117
-115
lines changed

__dependency_graph.dot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ digraph {
7676
DRuleParser -> DlFormula [color=blue]
7777
DRuleParser -> "boost/algorithm/string" [color=blue]
7878
DRuleParser -> iostream [color=blue]
79+
DRuleParser -> cstddef [color=red]
7980
DRuleParser -> map [color=red]
8081
DRuleParser -> memory [color=red]
8182
DRuleParser -> set [color=red]

helper/FctHelper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ bool cmpStringGrow::operator()(const string& a, const string& b) const {
2828

2929
unsigned FctHelper::digitsNum_uint32(uint32_t n) {
3030
static constexpr uint32_t MaxTable[9] = { 10u, 100u, 1000u, 10000u, 100000u, 1000000u, 10000000u, 100000000u, 1000000000u }; // to_string(numeric_limits<uint32_t>::max()) = "4294967295" has length 10
31-
return 1 + (upper_bound(MaxTable, MaxTable + 9, n) - MaxTable);
31+
return 1 + static_cast<unsigned>(upper_bound(MaxTable, MaxTable + 9, n) - MaxTable);
3232
}
3333

3434
unsigned FctHelper::digitsNum_uint64(uint64_t n) {
3535
static constexpr uint64_t MaxTable[19] = { 10uLL, 100uLL, 1000uLL, 10000uLL, 100000uLL, 1000000uLL, 10000000uLL, 100000000uLL, 1000000000uLL, 10000000000uLL, 100000000000uLL, 1000000000000uLL, 10000000000000uLL, 100000000000000uLL, 1000000000000000uLL, 10000000000000000uLL, 100000000000000000uLL, 1000000000000000000uLL, 10000000000000000000uLL }; // to_string(numeric_limits<uint64_t>::max()) = "18446744073709551615" has length 20
36-
return 1 + (upper_bound(MaxTable, MaxTable + 19, n) - MaxTable);
36+
return 1 + static_cast<unsigned>(upper_bound(MaxTable, MaxTable + 19, n) - MaxTable);
3737
}
3838

3939
string FctHelper::round(long double x, unsigned n, char separator) {
@@ -120,7 +120,7 @@ string FctHelper::durationYearsToMs(const chrono::microseconds& dur, bool innerA
120120
durationUs -= minutes * minuteUs;
121121
int64_t seconds = durationUs / secondUs;
122122
durationUs -= seconds * secondUs;
123-
double milliseconds = durationUs / 1000.0;
123+
double milliseconds = static_cast<double>(durationUs) / 1000.0;
124124

125125
stringstream ss;
126126
bool empty = true;
@@ -131,14 +131,14 @@ string FctHelper::durationYearsToMs(const chrono::microseconds& dur, bool innerA
131131
if (innerAlign && !empty) {
132132
if (negative)
133133
indent++;
134-
unsigned len = num.length();
134+
string::size_type len = num.length();
135135
if (indent <= len)
136136
return "";
137137
return string(indent - len, ' ');
138138
} else
139139
return "";
140140
};
141-
auto appendRequestedBlankIndent = [&](unsigned indent) {
141+
auto appendRequestedBlankIndent = [&](string::size_type indent) {
142142
if (innerAlign && !empty) {
143143
if (negative)
144144
indent++;
@@ -202,9 +202,9 @@ string FctHelper::durationYearsToMs(const chrono::microseconds& dur, bool innerA
202202
string FctHelper::durationStringMs(const chrono::microseconds& dur, bool innerAlign, unsigned round, bool showMonths, bool showWeeks, bool wolframAlphaMode, const string& yrId, const string& moId, const string& wkId, const string& dId, const string& hId, const string& minId, const string& sId, const string& msId) {
203203
stringstream ss;
204204
if (dur.count() >= 1000000)
205-
ss << FctHelper::round(dur.count() / 1000.0, 2) << msId << " (" << durationYearsToMs(dur, innerAlign, round, showMonths, showWeeks, wolframAlphaMode, yrId, moId, wkId, dId, hId, minId, sId, msId) << ")";
205+
ss << FctHelper::round(static_cast<long double>(dur.count()) / 1000.0, 2) << msId << " (" << durationYearsToMs(dur, innerAlign, round, showMonths, showWeeks, wolframAlphaMode, yrId, moId, wkId, dId, hId, minId, sId, msId) << ")";
206206
else
207-
ss << FctHelper::round(dur.count() / 1000.0, 2) << msId;
207+
ss << FctHelper::round(static_cast<long double>(dur.count()) / 1000.0, 2) << msId;
208208
return ss.str();
209209
}
210210

@@ -293,7 +293,7 @@ wstring FctHelper::utf8toWide(const char* in) {
293293

294294
vector<string> FctHelper::stringSplit(const string& str, const string& sep) {
295295
vector<string> parts;
296-
unsigned start = 0;
296+
string::size_type start = 0;
297297
string::size_type end = str.find(sep);
298298
while (end != string::npos) {
299299
parts.push_back(str.substr(start, end - start));

helper/ProgressData.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ProgressData::ProgressData(unsigned percentageStepSize, uint64_t maximum, bool e
1717
stepAmount--; // do not show 100% progress
1818
vector<uint64_t> steps(stepAmount);
1919
for (unsigned i = 0; i < stepAmount; i++)
20-
steps[i] = (uint64_t) ((double) maximum * (i + 1) * percentageStepSize / 100.0);
20+
steps[i] = static_cast<uint64_t>(static_cast<double>(maximum) * (i + 1) * percentageStepSize / 100.0);
2121
steps.push_back(0); // to avoid bound checks and never trigger at final state
2222
return steps;
2323
}()) {
@@ -28,8 +28,8 @@ ProgressData& ProgressData::operator=(const ProgressData& other) {
2828
maximum = other.maximum;
2929
maximumEstimated = other.maximumEstimated;
3030
progressSteps = other.progressSteps;
31-
progress = (uint64_t) other.progress;
32-
progressState = (uint64_t) other.progressState;
31+
progress = static_cast<uint64_t>(other.progress);
32+
progressState = static_cast<uint64_t>(other.progressState);
3333
return *this;
3434
}
3535

0 commit comments

Comments
 (0)