mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 05:13:35 +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:
@@ -73,7 +73,7 @@
|
||||
#include <uORB/uORB.h>
|
||||
|
||||
#include <float.h>
|
||||
#include <getopt.h>
|
||||
#include <px4_getopt.h>
|
||||
|
||||
#include "lps25h.h"
|
||||
|
||||
@@ -967,9 +967,12 @@ int
|
||||
lps25h_main(int argc, char *argv[])
|
||||
{
|
||||
enum LPS25H_BUS busid = LPS25H_BUS_ALL;
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "XIS:")) != EOF) {
|
||||
int myoptind = 1;
|
||||
int ch;
|
||||
const char *myoptarg = nullptr;
|
||||
|
||||
while ((ch = px4_getopt(argc, argv, "XIS:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
#if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_HMC)
|
||||
|
||||
@@ -992,7 +995,12 @@ lps25h_main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = argv[optind];
|
||||
if (myoptind >= argc) {
|
||||
lps25h::usage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
/*
|
||||
* Start/load the driver.
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <px4_getopt.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
@@ -70,7 +70,6 @@
|
||||
|
||||
#include <perf/perf_counter.h>
|
||||
#include <systemlib/err.h>
|
||||
#include <platforms/px4_getopt.h>
|
||||
|
||||
#include "mpl3115a2.h"
|
||||
|
||||
@@ -897,8 +896,8 @@ int
|
||||
mpl3115a2_main(int argc, char *argv[])
|
||||
{
|
||||
enum MPL3115A2_BUS busid = MPL3115A2_BUS_ALL;
|
||||
int ch;
|
||||
int myoptind = 1;
|
||||
int ch;
|
||||
const char *myoptarg = NULL;
|
||||
|
||||
/* jump over start/off/etc and look at options first */
|
||||
@@ -918,6 +917,11 @@ mpl3115a2_main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (myoptind >= argc) {
|
||||
mpl3115a2::usage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user