mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-18 16:09:06 +08:00
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:
parent
2de6192f66
commit
d1a7a367ac
@ -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++;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user