Skip to content

Commit f3fa6e8

Browse files
authored
Merge pull request #1503 from joto/fix-sign-conversions2
Fix more sign conversions
2 parents e99f334 + 04a71f3 commit f3fa6e8

File tree

9 files changed

+50
-26
lines changed

9 files changed

+50
-26
lines changed

src/expire-tiles.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ void expire_tiles::expire_tile(uint32_t x, uint32_t y)
116116
}
117117
}
118118

119-
int expire_tiles::normalise_tile_x_coord(int x)
119+
uint32_t expire_tiles::normalise_tile_x_coord(int x)
120120
{
121121
x %= map_width;
122122
if (x < 0) {
123123
x = (map_width - x) + 1;
124124
}
125-
return x;
125+
return static_cast<uint32_t>(x);
126126
}
127127

128128
void expire_tiles::coords_to_tile(double lon, double lat, double *tilex,
@@ -200,10 +200,12 @@ void expire_tiles::from_line(double lon_a, double lat_a, double lon_b,
200200
}
201201
for (int x = x1 - TILE_EXPIRY_LEEWAY; x <= x2 + TILE_EXPIRY_LEEWAY;
202202
++x) {
203-
int const norm_x = normalise_tile_x_coord(x);
203+
uint32_t const norm_x = normalise_tile_x_coord(x);
204204
for (int y = y1 - TILE_EXPIRY_LEEWAY; y <= y2 + TILE_EXPIRY_LEEWAY;
205205
++y) {
206-
expire_tile(norm_x, y);
206+
if (y >= 0) {
207+
expire_tile(norm_x, static_cast<uint32_t>(y));
208+
}
207209
}
208210
}
209211
}
@@ -256,10 +258,10 @@ int expire_tiles::from_bbox(double min_lon, double min_lat, double max_lon,
256258
max_tile_y = map_width;
257259
}
258260
for (int iterator_x = min_tile_x; iterator_x <= max_tile_x; ++iterator_x) {
259-
int const norm_x = normalise_tile_x_coord(iterator_x);
261+
uint32_t const norm_x = normalise_tile_x_coord(iterator_x);
260262
for (int iterator_y = min_tile_y; iterator_y <= max_tile_y;
261263
++iterator_y) {
262-
expire_tile(norm_x, iterator_y);
264+
expire_tile(norm_x, static_cast<uint32_t>(iterator_y));
263265
}
264266
}
265267
return 0;

src/expire-tiles.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ struct expire_tiles
178178
* \param y y index of the tile to be expired.
179179
*/
180180
void expire_tile(uint32_t x, uint32_t y);
181-
int normalise_tile_x_coord(int x);
181+
uint32_t normalise_tile_x_coord(int x);
182182
void from_line(double lon_a, double lat_a, double lon_b, double lat_b);
183183

184184
void from_wkb_point(ewkb::parser_t *wkb);

src/node-locations.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ bool node_locations_t::set(osmid_t id, osmium::Location location)
3434
m_index.add(id, m_data.size());
3535
}
3636

37-
protozero::add_varint_to_buffer(&m_data, m_did.update(id));
37+
auto const delta = m_did.update(id);
38+
// Always true because ids in input must be unique and ordered
39+
assert(delta > 0);
40+
protozero::add_varint_to_buffer(&m_data, static_cast<uint64_t>(delta));
41+
3842
protozero::add_varint_to_buffer(
3943
&m_data, protozero::encode_zigzag64(m_dx.update(location.x())));
4044
protozero::add_varint_to_buffer(
@@ -62,7 +66,8 @@ osmium::Location node_locations_t::get(osmid_t id) const
6266
osmium::DeltaDecode<int64_t> dy;
6367

6468
for (std::size_t n = 0; n < block_size && begin != end; ++n) {
65-
auto const bid = did.update(protozero::decode_varint(&begin, end));
69+
auto const bid = did.update(
70+
static_cast<int64_t>(protozero::decode_varint(&begin, end)));
6671
int32_t const x = dx.update(
6772
protozero::decode_zigzag64(protozero::decode_varint(&begin, end)));
6873
int32_t const y = dy.update(

src/options.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,24 @@ static osmium::Box parse_bbox(char const *bbox)
318318
return osmium::Box{minx, miny, maxx, maxy};
319319
}
320320

321+
static unsigned int number_of_threads(char const *arg)
322+
{
323+
int num = atoi(arg);
324+
if (num < 1) {
325+
log_warn("--number-processes must be at least 1. Using 1.");
326+
num = 1;
327+
} else if (num > 32) {
328+
// The threads will open up database connections which will
329+
// run out at some point. It depends on the number of tables
330+
// how many connections there are. The number 32 is way beyond
331+
// anything that will make sense here.
332+
log_warn("--number-processes too large. Set to 32.");
333+
num = 32;
334+
}
335+
336+
return static_cast<unsigned int>(num);
337+
}
338+
321339
options_t::options_t(int argc, char *argv[]) : options_t()
322340
{
323341
// If there are no command line arguments at all, show help.
@@ -503,18 +521,7 @@ options_t::options_t(int argc, char *argv[]) : options_t()
503521
log_warn("Deprecated option --cache-strategy ignored");
504522
break;
505523
case 205:
506-
num_procs = atoi(optarg);
507-
if (num_procs < 1) {
508-
log_warn("--number-processes must be at least 1. Using 1.");
509-
num_procs = 1;
510-
} else if (num_procs > 32) {
511-
// The threads will open up database connections which will
512-
// run out at some point. It depends on the number of tables
513-
// how many connections there are. The number 32 is way beyond
514-
// anything that will make sense here.
515-
log_warn("--number-processes too large. Set to 32.");
516-
num_procs = 32;
517-
}
524+
num_procs = number_of_threads(optarg);
518525
break;
519526
case 206:
520527
droptemp = true;

src/osmdata.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ class multithreaded_processor
347347

348348
void osmdata_t::process_dependents() const
349349
{
350-
multithreaded_processor proc{m_conninfo, m_mid, m_output,
351-
(std::size_t)m_num_procs};
350+
multithreaded_processor proc{m_conninfo, m_mid, m_output, m_num_procs};
352351

353352
// stage 1b processing: process parents of changed objects
354353
if (m_dependency_manager->has_pending()) {

src/osmdata.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class osmdata_t : public osmium::handler::Handler
9898
// imported).
9999
osmium::Box m_bbox;
100100

101-
int m_num_procs;
101+
unsigned int m_num_procs;
102102
bool m_append;
103103
bool m_droptemp;
104104
bool m_parallel_indexing;

src/pgsql-helper.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#include "format.hpp"
1111
#include "pgsql-helper.hpp"
1212

13+
#include <cassert>
14+
1315
idlist_t get_ids_from_result(pg_result_t const &result) {
1416
idlist_t ids;
15-
ids.reserve(result.num_tuples());
17+
assert(result.num_tuples() >= 0);
18+
ids.reserve(static_cast<std::size_t>(result.num_tuples()));
1619

1720
for (int i = 0; i < result.num_tuples(); ++i) {
1821
ids.push_back(osmium::string_to_object_id(result.get_value(i, 0)));

src/reprojection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <osmium/geom/mercator_projection.hpp>
1111

12+
#include "format.hpp"
1213
#include "reprojection.hpp"
1314

1415
namespace {
@@ -82,5 +83,9 @@ std::shared_ptr<reprojection> reprojection::create_projection(int srs)
8283
break;
8384
}
8485

86+
if (srs <= 0) {
87+
throw std::runtime_error{"Invalid projection SRID '{}'."_format(srs)};
88+
}
89+
8590
return make_generic_projection(srs);
8691
}

src/wkb.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ inline std::string create_point(double x, double y, uint32_t srid = 4326)
102102
class writer_t
103103
{
104104
public:
105-
explicit writer_t(uint32_t srid) : m_srid(srid) {}
105+
explicit writer_t(int srid) : m_srid(static_cast<uint32_t>(srid))
106+
{
107+
assert(srid > 0);
108+
}
106109

107110
void add_sub_geometry(std::string const &part)
108111
{

0 commit comments

Comments
 (0)