commit 1a45a19cc3c60085a757111ee6a5133e63538e13
parent bf0508d08c20b5e99cfc337d5dbccf162726f380
Author: Naveen Narayanan <zerous@nocebo.space>
Date: Sat, 18 Sep 2021 16:50:33 +0200
Return -1 if arg is NULL
* Emit error if atoi fails
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/parser.c b/parser.c
@@ -48,12 +48,17 @@ range(char *s, int min, int max)
{
int t;
+ if (!*s)
+ return -1;
+
errno = 0;
printf("range str: %s\n", s);
t = atoi(s);
printf("range t: %d\n", t);
- if (errno)
+ if (errno) {
+ fprintf(stderr, "atoi failed: %s\n", strerror(errno));
return -1;
+ }
if (t < min || t > max)
return -1;