driver: Fix crashes on missing cli arguments

This commit is contained in:
Martin Povišer 2024-02-12 14:56:10 +01:00
parent 46838172c2
commit 54a97f8bb7
1 changed files with 8 additions and 1 deletions

View File

@ -92,8 +92,15 @@ int getopt(int argc, char **argv, const char *optstring)
return optopt; return optopt;
} }
optarg = argv[++optind]; if (++optind >= argc) {
fprintf(stderr, "%s: option '-%c' expects an argument\n", argv[0], optopt);
optopt = '?';
return optopt;
}
optarg = argv[optind];
optind++, optcur = 1; optind++, optcur = 1;
return optopt; return optopt;
} }