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
+12 -4
View File
@@ -54,7 +54,7 @@
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <getopt.h>
#include <px4_getopt.h>
#include <perf/perf_counter.h>
#include <systemlib/err.h>
@@ -1932,12 +1932,15 @@ int
lsm303d_main(int argc, char *argv[])
{
bool external_bus = false;
int ch;
enum Rotation rotation = ROTATION_NONE;
int accel_range = 8;
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;
/* jump over start/off/etc and look at options first */
while ((ch = getopt(argc, argv, "XR:a:")) != EOF) {
while ((ch = px4_getopt(argc, argv, "XR:a:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'X':
external_bus = true;
@@ -1957,7 +1960,12 @@ lsm303d_main(int argc, char *argv[])
}
}
const char *verb = argv[optind];
if (myoptind >= argc) {
lsm303d::usage();
exit(0);
}
const char *verb = argv[myoptind];
/*
* Start/load the driver.