more robust -b and -j checking.
diff --git a/src/main.c b/src/main.c
index 92753da..00f4fa2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -34,6 +35,13 @@ int is_dir(const char * path) {
return 0;
}
+int is_numeric(const char * str) {
+ for (; *str; str++)
+ if (!isdigit(*str))
+ return 0;
+ return 1;
+}
+
int main(int argc, char * argv[]) {
// -1: decode, 0: unspecified, 1: encode, 2: test
int mode = 0;
@@ -59,11 +67,31 @@ int main(int argc, char * argv[]) {
} else if (argv[i][1] == 't') {
mode = 2;
} else if (argv[i][1] == 'b') {
+ if(i + 1 >= argc) {
+ fprintf(stderr, "Error: -b requires an argument.\n");
+ return 1;
+ }
+
+ if(!is_numeric(argv[i + 1])) {
+ fprintf(stderr, "Error: -b requires an integer argument.\n");
+ return 1;
+ }
+
block_size = MiB(atoi(argv[i + 1]));
i++;
} else if (argv[i][1] == 'c') {
force_stdstreams = 1;
} else if (argv[i][1] == 'j') {
+ if(i + 1 >= argc) {
+ fprintf(stderr, "Error: -j requires an argument.\n");
+ return 1;
+ }
+
+ if(!is_numeric(argv[i + 1])) {
+ fprintf(stderr, "Error: -j requires an integer argument.\n");
+ return 1;
+ }
+
workers = atoi(argv[i + 1]);
i++;
} else if(argv[i][1] == '-') {
