Skip to content

Commit 7e140d7

Browse files
committed
Fix implicit sign conversion in num_procs code
1 parent f78042a commit 7e140d7

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

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;

0 commit comments

Comments
 (0)