Skip to content

Commit 7811deb

Browse files
authored
Clarify render_list documentation (#388)
_Also_: * Added checks for `min` & `max` `x`, `y` & `z` tile coordinate options in order to: * Ensure they are integers * Ensure they are positive Resolves #387
1 parent 22a13e8 commit 7811deb

3 files changed

Lines changed: 84 additions & 27 deletions

File tree

docs/man/render_list.1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH RENDER_LIST "1" "2023-12-19" "mod_tile v0.7.0"
1+
.TH RENDER_LIST "1" "2024-02-06" "mod_tile v0.7.0"
22
.\" Please adjust this date whenever revising the manpage.
33

44
.SH NAME
@@ -51,6 +51,8 @@ Filter input to only render tiles greater or equal to this zoom level (default i
5151
Filter input to only render tiles less than or equal to this zoom level (default is 20).
5252
.PP
5353
If you are using --all, you can restrict the tile range by adding these options:
54+
.BR
55+
(please note that tile coordinates must be positive integers and are not latitude and longitude values)
5456
.BR
5557
-x, --min-x=X minimum X tile coordinate
5658
.BR

src/gen_tile_test.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,53 @@ TEST_CASE("render_list", "render list")
331331
ret = WEXITSTATUS(ret);
332332
REQUIRE(ret == 1);
333333
}
334+
335+
SECTION("render_list option is positive with --help", "should return 0") {
336+
std::string option = GENERATE("--max-load", "--max-x", "--max-y", "--max-zoom", "--min-x", "--min-y", "--min-zoom", "--num-threads");
337+
std::string command = "./render_list " + option + " 1 --help";
338+
339+
// flawfinder: ignore
340+
int ret = system(command.c_str());
341+
ret = WEXITSTATUS(ret);
342+
REQUIRE(ret == 0);
343+
}
344+
345+
SECTION("render_list option is negative", "should return 1") {
346+
std::string option = GENERATE("--max-load", "--max-x", "--max-y", "--max-zoom", "--min-x", "--min-y", "--min-zoom", "--num-threads");
347+
std::string command = "./render_list " + option + " -1";
348+
349+
// flawfinder: ignore
350+
int ret = system(command.c_str());
351+
ret = WEXITSTATUS(ret);
352+
REQUIRE(ret == 1);
353+
}
354+
355+
SECTION("render_list option is float", "should return 1") {
356+
std::string option = GENERATE("--max-load", "--max-x", "--max-y", "--max-zoom", "--min-x", "--min-y", "--min-zoom", "--num-threads");
357+
std::string command = "./render_list " + option + " 0.12345";
358+
359+
// flawfinder: ignore
360+
int ret = system(command.c_str());
361+
ret = WEXITSTATUS(ret);
362+
REQUIRE(ret == 1);
363+
}
364+
365+
SECTION("render_list num threads subceeds minimum of 1", "should return 1") {
366+
// flawfinder: ignore
367+
int ret = system("./render_list -n 0");
368+
ret = WEXITSTATUS(ret);
369+
REQUIRE(ret == 1);
370+
}
371+
372+
SECTION("render_list zoom exceeds maximum of MAX_ZOOM", "should return 1") {
373+
std::string option = GENERATE("--max-zoom", "--min-zoom");
374+
std::string command = "./render_list " + option + " 1000";
375+
376+
// flawfinder: ignore
377+
int ret = system(command.c_str());
378+
ret = WEXITSTATUS(ret);
379+
REQUIRE(ret == 1);
380+
}
334381
}
335382

336383
TEST_CASE("render_old", "render old")

src/render_list.c

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ void display_rate(struct timeval start, struct timeval end, int num)
7575
fflush(NULL);
7676
}
7777

78+
int min_max_opt(char *opt_arg, char *opt_type_name, int minimum, int maximum)
79+
{
80+
int opt = atoi(opt_arg);
81+
float opt_float;
82+
83+
if (minimum != -1 && opt < minimum) {
84+
fprintf(stderr, "Invalid %s, must be >= %i (%s was provided)\n", opt_type_name, minimum, opt_arg);
85+
exit(1);
86+
}
87+
88+
if (maximum != -1 && opt > maximum) {
89+
fprintf(stderr, "Invalid %s, must be <= %i (%s was provided)\n", opt_type_name, maximum, opt_arg);
90+
exit(1);
91+
}
92+
93+
if (sscanf(opt_arg, "%f", &opt_float) != 0) {
94+
if ((float) opt != opt_float) {
95+
fprintf(stderr, "Invalid %s, must be an integer (%s was provided)\n", opt_type_name, opt_arg);
96+
exit(1);
97+
}
98+
}
99+
100+
return opt;
101+
}
102+
78103
int main(int argc, char **argv)
79104
{
80105
char *spath = strdup(RENDERD_SOCKET);
@@ -141,53 +166,35 @@ int main(int argc, char **argv)
141166
break;
142167

143168
case 'l': /* -l, --max-load */
144-
maxLoad = atoi(optarg);
169+
maxLoad = min_max_opt(optarg, "maximum load", 0, -1);
145170
break;
146171

147172
case 'n': /* -n, --num-threads */
148-
numThreads = atoi(optarg);
149-
150-
if (numThreads <= 0) {
151-
fprintf(stderr, "Invalid number of threads, must be at least 1\n");
152-
return 1;
153-
}
154-
173+
numThreads = min_max_opt(optarg, "number of threads", 1, -1);
155174
break;
156175

157176
case 'x': /* -x, --min-x */
158-
minX = atoi(optarg);
177+
minX = min_max_opt(optarg, "minimum X tile coordinate", 0, -1);
159178
break;
160179

161180
case 'X': /* -X, --max-x */
162-
maxX = atoi(optarg);
181+
maxX = min_max_opt(optarg, "maximum X tile coordinate", 0, -1);
163182
break;
164183

165184
case 'y': /* -y, --min-y */
166-
minY = atoi(optarg);
185+
minY = min_max_opt(optarg, "minimum Y tile coordinate", 0, -1);
167186
break;
168187

169188
case 'Y': /* -Y, --max-y */
170-
maxY = atoi(optarg);
189+
maxY = min_max_opt(optarg, "maximum Y tile coordinate", 0, -1);
171190
break;
172191

173192
case 'z': /* -z, --min-zoom */
174-
minZoom = atoi(optarg);
175-
176-
if (minZoom < 0 || minZoom > MAX_ZOOM) {
177-
fprintf(stderr, "Invalid minimum zoom selected, must be between 0 and %d\n", MAX_ZOOM);
178-
return 1;
179-
}
180-
193+
minZoom = min_max_opt(optarg, "minimum zoom", 0, MAX_ZOOM);
181194
break;
182195

183196
case 'Z': /* -Z, --max-zoom */
184-
maxZoom = atoi(optarg);
185-
186-
if (maxZoom < 0 || maxZoom > MAX_ZOOM) {
187-
fprintf(stderr, "Invalid maximum zoom selected, must be between 0 and %d\n", MAX_ZOOM);
188-
return 1;
189-
}
190-
197+
maxZoom = min_max_opt(optarg, "maximum zoom", 0, MAX_ZOOM);
191198
break;
192199

193200
case 'f': /* -f, --force */
@@ -211,6 +218,7 @@ int main(int argc, char **argv)
211218
fprintf(stderr, " -z, --min-zoom=ZOOM filter input to only render tiles greater or equal to this zoom level (default is 0)\n");
212219
fprintf(stderr, "\n");
213220
fprintf(stderr, "If you are using --all, you can restrict the tile range by adding these options:\n");
221+
fprintf(stderr, " (please note that tile coordinates must be positive integers and are not latitude and longitude values)\n");
214222
fprintf(stderr, " -X, --max-x=X maximum X tile coordinate\n");
215223
fprintf(stderr, " -x, --min-x=X minimum X tile coordinate\n");
216224
fprintf(stderr, " -Y, --max-y=Y maximum Y tile coordinate\n");

0 commit comments

Comments
 (0)