using only px4_getopt() and never the unsafe getopt()

using only <px4_getopt.h> as include, cleanup related includes
added check that all the option are valid (myoptind >= argc). if there are invalid options on some script that might now lead not to run commands
This commit is contained in:
bazooka joe
2019-02-21 09:45:45 +01:00
committed by Beat Küng
parent 3db901b238
commit 922c19aa9c
20 changed files with 131 additions and 50 deletions
+8 -4
View File
@@ -61,6 +61,7 @@
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <px4_getopt.h>
#include <nuttx/wqueue.h>
#include <nuttx/clock.h>
@@ -531,10 +532,13 @@ pca9685_main(int argc, char *argv[])
int i2cdevice = -1;
int i2caddr = ADDR; // 7bit
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;
// jump over start/off/etc and look at options first
while ((ch = getopt(argc, argv, "a:b:")) != EOF) {
while ((ch = px4_getopt(argc, argv, "a:b:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'a':
i2caddr = strtol(optarg, NULL, 0);
@@ -550,12 +554,12 @@ pca9685_main(int argc, char *argv[])
}
}
if (optind >= argc) {
if (myoptind >= argc) {
pca9685_usage();
exit(1);
exit(0);
}
const char *verb = argv[optind];
const char *verb = argv[myoptind];
int fd;
int ret;