From 1af374e8892e97d0c2e826a5de0ad7b37fe9238f Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 21 Aug 2017 18:18:27 +0200 Subject: check -n parameter, use strtoll to allow hex and octal --- holes.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/holes.c b/holes.c index 865ea50..c618a8e 100644 --- a/holes.c +++ b/holes.c @@ -49,13 +49,27 @@ int main(int argc, char *argv[]) { int c, i; + char *e; argv0 = argv[0]; while ((c = getopt(argc, argv, "n:")) != -1) switch(c) { case 'n': - minlen = atoll(optarg); + errno = 0; + minlen = strtoll(optarg, &e, 0); + if (errno != 0 || *e) { + fprintf(stderr, + "%s: can't parse length '%s'.\n", + argv0, optarg); + exit(2); + } + if (minlen < 1) { + fprintf(stderr, + "%s: MINLEN must not be smaller than 1.\n", + argv0); + exit(2); + } break; default: fprintf(stderr, @@ -63,12 +77,6 @@ main(int argc, char *argv[]) exit(2); } - if (minlen < 1) { - fprintf(stderr, "%s: MINLEN must not be smaller than 1.\n", - argv0); - exit(2); - } - if (optind == argc) holes(stdin, 0); else -- cgit 1.4.1