fix px4_getopt: add argc check for options that take an argument

Fixes the following corner case:
mpu9250 start -R
This would return a valid result (myoptind < argc), but myoptind pointed
to a NULL argument (and thus mpu9250 would crash).
With this patch, px4_getopt will return '?', indicating a parser error.
This commit is contained in:
Beat Küng 2018-06-04 14:38:28 +02:00 committed by Lorenz Meier
parent 2de6192f66
commit d1a7a367ac

View File

@ -82,6 +82,10 @@ static int reorder(int argc, char **argv, const char *options)
tmpidx++;
if (takesarg) {
if (idx + 1 >= argc) { //Error: option takes an argument, but there is no more argument
return 1;
}
tmp_argv[tmpidx] = argv[idx + 1];
// printf("tmp_argv[%d] = %s\n", tmpidx, tmp_argv[tmpidx]);
tmpidx++;