mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 05:53: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:
@@ -42,6 +42,7 @@
|
||||
*/
|
||||
|
||||
#include "batt_smbus.h"
|
||||
#include <px4_getopt.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -100,9 +101,12 @@ BATT_SMBUS::~BATT_SMBUS()
|
||||
int BATT_SMBUS::task_spawn(int argc, char *argv[])
|
||||
{
|
||||
enum BATT_SMBUS_BUS busid = BATT_SMBUS_BUS_ALL;
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "XTRIA:")) != EOF) {
|
||||
int myoptind = 1;
|
||||
int ch;
|
||||
const char *myoptarg = nullptr;
|
||||
|
||||
while ((ch = px4_getopt(argc, argv, "XTRIA:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'X':
|
||||
busid = BATT_SMBUS_BUS_I2C_EXTERNAL;
|
||||
@@ -130,6 +134,11 @@ int BATT_SMBUS::task_spawn(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (myoptind >= argc) {
|
||||
print_usage();
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < NUM_BUS_OPTIONS; i++) {
|
||||
|
||||
if (!is_running() && (busid == BATT_SMBUS_BUS_ALL || bus_options[i].busid == busid)) {
|
||||
|
||||
Reference in New Issue
Block a user