From dc78467ebc7df9bfad81ed6e30f74139440ab159 Mon Sep 17 00:00:00 2001 From: Hampus Date: Wed, 5 Jan 2022 21:45:49 +0100 Subject: fix: add better number handling --- src/mazerator.c | 11 ++++++++++- src/utils.c | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mazerator.c b/src/mazerator.c index 8224fb9..593d518 100644 --- a/src/mazerator.c +++ b/src/mazerator.c @@ -72,6 +72,9 @@ int main(int argc, char *argv[]) if (err != NULL) optarg_error(arg, err); + if (maze_width == 0) + optarg_error(arg, "It should not be 0"); + break; case 'h': maze_height = str_to_uint(optarg, &err); @@ -79,6 +82,9 @@ int main(int argc, char *argv[]) if (err != NULL) optarg_error(arg, err); + if (maze_height == 0) + optarg_error(arg, "It should not be 0"); + break; case 'x': start_x = malloc_s(sizeof(unsigned int *)); @@ -106,6 +112,9 @@ int main(int argc, char *argv[]) if (err != NULL) optarg_error(arg, err); + if (*seed == 0) + optarg_error(arg, "It should not be 0"); + break; case 0: printf("Usage: %s [OPTION]...\n\n" @@ -119,7 +128,7 @@ int main(int argc, char *argv[]) " -W, --wall WALL Single character used as maze walls " "(Default: '█')\n" " -s, --seed SEED The randomization seed used for maze " - "generation (Any number)\n" + "generation\n" " --help Displays usage information\n", argv[0]); exit(0); diff --git a/src/utils.c b/src/utils.c index 69ce55d..da48ef6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -33,7 +33,7 @@ unsigned int str_to_uint(char *str, char **err) { if (*str == '-') { - *err = "Not greater than 0"; + *err = "Less than 0"; return 0; } -- cgit v1.2.3-18-g5258