mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 02:03:34 +08:00
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:
@@ -58,7 +58,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>
|
||||
@@ -1780,10 +1780,13 @@ int
|
||||
adis16448_main(int argc, char *argv[])
|
||||
{
|
||||
enum Rotation rotation = ROTATION_NONE;
|
||||
|
||||
int myoptind = 1;
|
||||
int ch;
|
||||
const char *myoptarg = nullptr;
|
||||
|
||||
/* start options */
|
||||
while ((ch = getopt(argc, argv, "R:")) != EOF) {
|
||||
while ((ch = px4_getopt(argc, argv, "R:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'R':
|
||||
rotation = (enum Rotation)atoi(optarg);
|
||||
@@ -1795,7 +1798,13 @@ adis16448_main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = argv[optind];
|
||||
if (myoptind >= argc) {
|
||||
adis16448::usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
|
||||
/*
|
||||
* Start/load the driver.
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include "ADIS16477.hpp"
|
||||
|
||||
#include <px4_getopt.h>
|
||||
|
||||
#define ADIS16477_DEVICE_PATH_ACCEL "/dev/adis16477_accel"
|
||||
#define ADIS16477_DEVICE_PATH_GYRO "/dev/adis16477_gyro"
|
||||
|
||||
@@ -215,10 +217,13 @@ int
|
||||
adis16477_main(int argc, char *argv[])
|
||||
{
|
||||
enum Rotation rotation = ROTATION_NONE;
|
||||
|
||||
int myoptind = 1;
|
||||
int ch;
|
||||
const char *myoptarg = nullptr;
|
||||
|
||||
/* start options */
|
||||
while ((ch = getopt(argc, argv, "R:")) != EOF) {
|
||||
while ((ch = px4_getopt(argc, argv, "R:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'R':
|
||||
rotation = (enum Rotation)atoi(optarg);
|
||||
@@ -226,11 +231,16 @@ adis16477_main(int argc, char *argv[])
|
||||
|
||||
default:
|
||||
adis16477::usage();
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = argv[optind];
|
||||
if (myoptind >= argc) {
|
||||
adis16477::usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
/*
|
||||
* Start/load the driver.
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "BMI055_gyro.hpp"
|
||||
|
||||
#include <px4_config.h>
|
||||
#include <platforms/px4_getopt.h>
|
||||
#include <px4_getopt.h>
|
||||
|
||||
/** driver 'main' command */
|
||||
extern "C" { __EXPORT int bmi055_main(int argc, char *argv[]); }
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include <perf/perf_counter.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
#include <board_config.h>
|
||||
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
||||
#include <lib/conversion/rotation.h>
|
||||
#include <platforms/px4_getopt.h>
|
||||
#include <px4_getopt.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
/* SPI protocol address bits */
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
#include <board_config.h>
|
||||
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
||||
#include <lib/conversion/rotation.h>
|
||||
#include <platforms/px4_getopt.h>
|
||||
#include <px4_getopt.h>
|
||||
#include <systemlib/err.h>
|
||||
|
||||
/* SPI protocol address bits */
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user