We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ea6d93 commit 193ac44Copy full SHA for 193ac44
2 files changed
src/command-line-parser.cpp
@@ -18,13 +18,15 @@
18
#include "util.hpp"
19
#include "version.hpp"
20
21
+#include <osmium/util/string.hpp>
22
#include <osmium/version.hpp>
23
24
#include <CLI/CLI.hpp>
25
26
#include <lua.hpp>
27
28
#include <algorithm>
29
+#include <cmath>
30
#include <cstdio>
31
#include <cstring>
32
#include <stdexcept>
@@ -33,21 +35,36 @@
33
35
34
36
namespace {
37
-osmium::Box parse_bbox_param(std::string const &arg)
38
+void error_bbox()
39
+{
40
+ throw std::runtime_error{"Bounding box must be specified like: "
41
+ "minlon,minlat,maxlon,maxlat."};
42
+}
43
+
44
+double parse_and_check_coordinate(std::string const &str)
45
{
- double minx = NAN;
- double maxx = NAN;
- double miny = NAN;
- double maxy = NAN;
46
+ char *end = nullptr;
47
48
+ double const value = std::strtod(str.c_str(), &end);
49
+ if (end != &*str.end() || !std::isfinite(value)) {
50
+ error_bbox();
51
+ }
52
- int const n =
- sscanf(arg.c_str(), "%lf,%lf,%lf,%lf", &minx, &miny, &maxx, &maxy);
53
+ return value;
54
55
- if (n != 4) {
- throw std::runtime_error{"Bounding box must be specified like: "
- "minlon,minlat,maxlon,maxlat."};
56
+osmium::Box parse_bbox_param(std::string const &arg)
57
58
+ auto const values = osmium::split_string(arg, ',', true);
59
+ if (values.size() != 4) {
60
61
}
62
63
+ double const minx = parse_and_check_coordinate(values[0]);
64
+ double const miny = parse_and_check_coordinate(values[1]);
65
+ double const maxx = parse_and_check_coordinate(values[2]);
66
+ double const maxy = parse_and_check_coordinate(values[3]);
67
68
if (maxx <= minx) {
69
throw std::runtime_error{
70
"Bounding box failed due to maxlon <= minlon."};
@@ -60,7 +77,12 @@ osmium::Box parse_bbox_param(std::string const &arg)
77
78
log_debug("Applying bounding box: {},{} to {},{}", minx, miny, maxx, maxy);
79
- return osmium::Box{minx, miny, maxx, maxy};
80
+ osmium::Box const box{minx, miny, maxx, maxy};
81
+ if (!box.valid()) {
82
83
84
85
+ return box;
86
87
88
void parse_expire_tiles_param(char const *arg, uint32_t *expire_tiles_zoom_min,
tests/test-options-parse.cpp
@@ -89,6 +89,24 @@ TEST_CASE("Parsing bbox fails if wrong format", "[NoDB]")
89
90
bad_opt({"-b", "123"}, "Bounding box must be specified like:"
91
" minlon,minlat,maxlon,maxlat.");
92
93
+ bad_opt({"-b", "1,2,3,4x"}, "Bounding box must be specified like:"
94
+ " minlon,minlat,maxlon,maxlat.");
95
96
+ bad_opt({"-b", "1,,3,4"}, "Bounding box must be specified like:"
97
98
99
+ bad_opt({"-b", "1,2,3"}, "Bounding box must be specified like:"
100
101
102
+ bad_opt({"-b", "1,2,3,4,5"}, "Bounding box must be specified like:"
103
104
105
+ bad_opt({"-b", "1,2,INF,4"}, "Bounding box must be specified like:"
106
107
108
+ bad_opt({"-b", "1,NAN,3,4"}, "Bounding box must be specified like:"
109
110
111
112
TEST_CASE("Parsing number-processes", "[NoDB]")
0 commit comments