about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-08-21 18:18:27 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-08-21 18:18:27 +0200
commit1af374e8892e97d0c2e826a5de0ad7b37fe9238f (patch)
tree5319fb7e5fd8b4ceac3748fb02265ca40f2a4c65
parentb5803897df7792d3137e8050ef3c3fb96288d24a (diff)
downloadholes-1af374e8892e97d0c2e826a5de0ad7b37fe9238f.tar.gz
holes-1af374e8892e97d0c2e826a5de0ad7b37fe9238f.tar.xz
holes-1af374e8892e97d0c2e826a5de0ad7b37fe9238f.zip
check -n parameter, use strtoll to allow hex and octal
-rw-r--r--holes.c22
1 files 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