Skip to content

Commit d8dd191

Browse files
authored
Merge pull request #1846 from joto/explicit-conversions
Do some explicit number conversions
2 parents 8145192 + c2ee961 commit d8dd191

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

src/flex-lua-geom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int geom_centroid(lua_State *lua_state)
9898
static int geom_geometry_n(lua_State *lua_state)
9999
{
100100
auto const *const input_geometry = unpack_geometry(lua_state);
101-
int const index = luaL_checkinteger(lua_state, 2);
101+
auto const index = static_cast<int>(luaL_checkinteger(lua_state, 2));
102102

103103
try {
104104
auto *geom = create_lua_geometry_object(lua_state);
@@ -216,7 +216,7 @@ static int geom_tostring(lua_State *lua_state)
216216
static int geom_transform(lua_State *lua_state)
217217
{
218218
auto const *const input_geometry = unpack_geometry(lua_state);
219-
int const srid = luaL_checkinteger(lua_state, 2);
219+
auto const srid = static_cast<int>(luaL_checkinteger(lua_state, 2));
220220

221221
try {
222222
if (input_geometry->srid() != 4326) {

src/geom-functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ void line_merge(geometry_t *output, geometry_t const &input)
548548
std::vector<endpoint_t> endpoints;
549549

550550
// ...and a list of connections.
551-
constexpr std::size_t const NOCONN = -1UL;
551+
constexpr auto const NOCONN = std::numeric_limits<std::size_t>::max();
552552

553553
struct connection_t
554554
{

src/node-locations.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ osmium::Location node_locations_t::get(osmid_t id) const
6565
for (std::size_t n = 0; n < block_size && begin != end; ++n) {
6666
auto const bid = did.update(
6767
static_cast<int64_t>(protozero::decode_varint(&begin, end)));
68-
int32_t const x = dx.update(
69-
protozero::decode_zigzag64(protozero::decode_varint(&begin, end)));
70-
int32_t const y = dy.update(
71-
protozero::decode_zigzag64(protozero::decode_varint(&begin, end)));
68+
auto const x = static_cast<int32_t>(dx.update(
69+
protozero::decode_zigzag64(protozero::decode_varint(&begin, end))));
70+
auto const y = static_cast<int32_t>(dy.update(
71+
protozero::decode_zigzag64(protozero::decode_varint(&begin, end))));
7272
if (bid == id) {
7373
return osmium::Location{x, y};
7474
}

src/progress-display.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static double count_per_second(std::size_t count, uint64_t elapsed) noexcept
1919
}
2020

2121
if (elapsed == 0) {
22-
return count;
22+
return static_cast<double>(count);
2323
}
2424

2525
return static_cast<double>(count) / elapsed;
@@ -115,4 +115,3 @@ uint64_t progress_display_t::overall_time(std::time_t now) const noexcept
115115
{
116116
return static_cast<uint64_t>(now - m_node.start);
117117
}
118-

src/tagtransform-lua.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ bool lua_tagtransform_t::filter_rel_member_tags(
186186
lua_newtable(lua_state()); /* member roles table */
187187

188188
for (size_t i = 0; i < num_members; ++i) {
189-
lua_pushnumber(lua_state(), i + 1);
189+
lua_pushnumber(lua_state(), static_cast<lua_Number>(i + 1));
190190
lua_pushstring(lua_state(), member_roles[i]);
191191
lua_rawset(lua_state(), -3);
192192
}
193193

194-
lua_pushnumber(lua_state(), num_members);
194+
lua_pushnumber(lua_state(), static_cast<lua_Number>(num_members));
195195

196196
if (lua_pcall(lua_state(), 4, 6, 0)) {
197197
/* lua function failed */

src/util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ class timer_t
110110
*
111111
* Returns 0 if the elapsed time is 0.
112112
*/
113-
double per_second(double value) const noexcept
113+
double per_second(std::size_t value) const noexcept
114114
{
115115
auto const seconds =
116116
std::chrono::duration_cast<std::chrono::seconds>(m_duration)
117117
.count();
118118
if (seconds == 0) {
119119
return 0.0;
120120
}
121-
return value / static_cast<double>(seconds);
121+
return static_cast<double>(value) / static_cast<double>(seconds);
122122
}
123123

124124
private:

src/wkb.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ class ewkb_parser_t
309309
{
310310
public:
311311
ewkb_parser_t(char const *it, char const *end)
312-
: m_it(it), m_end(end), m_max_length((end - it) / (sizeof(double) * 2))
312+
: m_it(it), m_end(end),
313+
m_max_length(static_cast<uint32_t>(end - it) / (sizeof(double) * 2))
313314
{}
314315

315316
geom::geometry_t operator()()

tests/test-parse-osmium.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ struct counting_output_t : public output_null_t
124124

125125
type_stats_t node, way, relation;
126126
long long sum_ids = 0;
127-
unsigned sum_nds = 0;
128-
unsigned sum_members = 0;
127+
std::size_t sum_nds = 0;
128+
std::size_t sum_members = 0;
129129
};
130130

131131
struct counts_t {

0 commit comments

Comments
 (0)