Skip to content

Commit ecb62f3

Browse files
committed
driver: Fix crashes on missing cli arguments
1 parent 2098967 commit ecb62f3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

kernel/driver.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ int getopt(int argc, char **argv, const char *optstring)
9292
return optopt;
9393
}
9494

95-
optarg = argv[++optind];
95+
if (++optind >= argc) {
96+
fprintf(stderr, "%s: option '-%c' expects an argument\n", argv[0], optopt);
97+
optopt = '?';
98+
return optopt;
99+
}
100+
101+
optarg = argv[optind];
96102
optind++, optcur = 1;
103+
97104
return optopt;
98105
}
99106

0 commit comments

Comments
 (0)