Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various getopt & argc index check fixes #9589

Merged
merged 24 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8bb82d
bmp280: add argc check and use px4_getopt
bkueng Jun 4, 2018
11e4173
lps22hb: add argc check and use px4_getopt
bkueng Jun 4, 2018
3b09951
ms5611: add argc check
bkueng Jun 4, 2018
14b3c0b
ets_airspeed: add argc check and use px4_getopt
bkueng Jun 4, 2018
4ea774e
ms4525: add argc check and use px4_getopt
bkueng Jun 4, 2018
5c37204
ms5525: add argc check and use px4_getopt
bkueng Jun 4, 2018
b77c457
sdp3x: add argc check and use px4_getopt
bkueng Jun 4, 2018
3352971
mb12xx: add argc check and fix argv index
bkueng Jun 4, 2018
bd63ed5
sf0x: add argc check and fix argv index
bkueng Jun 4, 2018
da6c2f7
sf1xx: add argc check
bkueng Jun 4, 2018
5b6009a
srf02: add argc check
bkueng Jun 4, 2018
01fde13
teraranger: add argc check and fix argv index
bkueng Jun 4, 2018
84421af
tfmini: add argc check and fix argv index
bkueng Jun 4, 2018
82ba0be
bma180: add argc check
bkueng Jun 4, 2018
35c72ea
bmi160: add argc check and use px4_getopt
bkueng Jun 4, 2018
c2f7573
mpu6000: add argc check and use px4_getopt
bkueng Jun 4, 2018
e3e8e98
mpu9250: add argc check and use px4_getopt
bkueng Jun 4, 2018
a75b0ff
bmm150: add argc check and use px4_getopt
bkueng Jun 4, 2018
896c511
lis3mdl: add argc check and use px4_getopt
bkueng Jun 4, 2018
b4c7f3f
pwm_input: add argc check
bkueng Jun 4, 2018
9c8ebde
iridiumsbd: add argc check
bkueng Jun 4, 2018
93c4a2e
test_ppm: add argc check
bkueng Jun 4, 2018
9c20608
position_estimator_inav: add missing return
bkueng Jun 4, 2018
3b70392
fix px4_getopt: add argc check for options that take an argument
bkueng Jun 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/drivers/barometer/bmp280/bmp280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <getopt.h>
#include <px4_getopt.h>
#include <px4_log.h>

#include <nuttx/arch.h>
Expand Down Expand Up @@ -849,20 +849,19 @@ usage()
int
bmp280_main(int argc, char *argv[])
{
enum BMP280_BUS busid = BMP280_BUS_ALL;
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;
enum BMP280_BUS busid = BMP280_BUS_ALL;

/* jump over start/off/etc and look at options first */
while ((ch = getopt(argc, argv, "XISs")) != EOF) {
while ((ch = px4_getopt(argc, argv, "XISs", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'X':
busid = BMP280_BUS_I2C_EXTERNAL;
break;

case 'I':
busid = BMP280_BUS_I2C_INTERNAL;
//PX4_ERR("not supported yet");
//exit(1);
break;

case 'S':
Expand All @@ -875,11 +874,16 @@ bmp280_main(int argc, char *argv[])

default:
bmp280::usage();
exit(0);
return 0;
}
}

const char *verb = argv[optind];
if (myoptind >= argc) {
bmp280::usage();
return -1;
}

const char *verb = argv[myoptind];

/*
* Start/load the driver.
Expand Down Expand Up @@ -910,5 +914,5 @@ bmp280_main(int argc, char *argv[])
}

PX4_ERR("unrecognized command, try 'start', 'test', 'reset' or 'info'");
exit(1);
return -1;
}
1 change: 0 additions & 1 deletion src/drivers/barometer/lps22hb/LPS22HB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <uORB/uORB.h>

#include <float.h>
#include <getopt.h>

static constexpr uint8_t WHO_AM_I = 0x0F;
static constexpr uint8_t LPS22HB_ID_WHO_AM_I = 0xB1;
Expand Down
18 changes: 14 additions & 4 deletions src/drivers/barometer/lps22hb/lps22hb_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include "LPS22HB.hpp"

#include <px4_getopt.h>

#include <cstring>

extern "C" __EXPORT int lps22hb_main(int argc, char *argv[]);
Expand Down Expand Up @@ -234,10 +236,13 @@ usage()
int
lps22hb_main(int argc, char *argv[])
{
enum LPS22HB_BUS busid = LPS22HB_BUS_ALL;
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;

enum LPS22HB_BUS busid = LPS22HB_BUS_ALL;

while ((ch = getopt(argc, argv, "XIS:")) != EOF) {
while ((ch = px4_getopt(argc, argv, "XIS:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
#if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_HMC)

Expand All @@ -256,11 +261,16 @@ lps22hb_main(int argc, char *argv[])

default:
lps22hb::usage();
exit(0);
return 0;
}
}

const char *verb = argv[optind];
if (myoptind >= argc) {
lps22hb::usage();
return -1;
}

const char *verb = argv[myoptind];

/*
* Start/load the driver.
Expand Down
11 changes: 8 additions & 3 deletions src/drivers/barometer/ms5611/ms5611.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <getopt.h>

#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
Expand Down Expand Up @@ -1198,10 +1197,15 @@ ms5611_main(int argc, char *argv[])

default:
ms5611::usage();
exit(0);
return 0;
}
}

if (myoptind >= argc) {
ms5611::usage();
return -1;
}

const char *verb = argv[myoptind];

/*
Expand Down Expand Up @@ -1232,5 +1236,6 @@ ms5611_main(int argc, char *argv[])
ms5611::info();
}

errx(1, "unrecognised command, try 'start', 'test', 'reset' or 'info'");
PX4_ERR("unrecognised command, try 'start', 'test', 'reset' or 'info'");
return -1;
}
33 changes: 22 additions & 11 deletions src/drivers/differential_pressure/ets/ets_airspeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <systemlib/err.h>
#include <parameters/param.h>
#include <perf/perf_counter.h>
#include <px4_getopt.h>

#include <drivers/drv_airspeed.h>
#include <drivers/drv_hrt.h>
Expand Down Expand Up @@ -357,38 +358,48 @@ ets_airspeed_main(int argc, char *argv[])
{
int i2c_bus = PX4_I2C_BUS_DEFAULT;

int i;
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;

for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) {
if (argc > i + 1) {
i2c_bus = atoi(argv[i + 1]);
}
while ((ch = px4_getopt(argc, argv, "b:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'b':
i2c_bus = atoi(myoptarg);
break;

default:
ets_airspeed_usage();
return 0;
}
}

if (myoptind >= argc) {
ets_airspeed_usage();
return -1;
}

/*
* Start/load the driver.
*/
if (!strcmp(argv[1], "start")) {
if (!strcmp(argv[myoptind], "start")) {
return ets_airspeed::start(i2c_bus);
}

/*
* Stop the driver
*/
if (!strcmp(argv[1], "stop")) {
if (!strcmp(argv[myoptind], "stop")) {
return ets_airspeed::stop();
}

/*
* Reset the driver.
*/
if (!strcmp(argv[1], "reset")) {
if (!strcmp(argv[myoptind], "reset")) {
return ets_airspeed::reset();
}

ets_airspeed_usage();

return PX4_OK;
return 0;
}
33 changes: 22 additions & 11 deletions src/drivers/differential_pressure/ms4525/ms4525_airspeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
*/

#include <px4_config.h>
#include <px4_getopt.h>

#include <drivers/device/i2c.h>

Expand Down Expand Up @@ -493,38 +494,48 @@ ms4525_airspeed_main(int argc, char *argv[])
{
int i2c_bus = PX4_I2C_BUS_DEFAULT;

int i;
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;

for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) {
if (argc > i + 1) {
i2c_bus = atoi(argv[i + 1]);
}
while ((ch = px4_getopt(argc, argv, "b:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'b':
i2c_bus = atoi(myoptarg);
break;

default:
meas_airspeed_usage();
return 0;
}
}

if (myoptind >= argc) {
meas_airspeed_usage();
return -1;
}

/*
* Start/load the driver.
*/
if (!strcmp(argv[1], "start")) {
if (!strcmp(argv[myoptind], "start")) {
return meas_airspeed::start(i2c_bus);
}

/*
* Stop the driver
*/
if (!strcmp(argv[1], "stop")) {
if (!strcmp(argv[myoptind], "stop")) {
return meas_airspeed::stop();
}

/*
* Reset the driver.
*/
if (!strcmp(argv[1], "reset")) {
if (!strcmp(argv[myoptind], "reset")) {
return meas_airspeed::reset();
}

meas_airspeed_usage();

return PX4_OK;
return 0;
}
34 changes: 24 additions & 10 deletions src/drivers/differential_pressure/ms5525/MS5525_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include "MS5525.hpp"

#include <px4_getopt.h>

// Driver 'main' command.
extern "C" __EXPORT int ms5525_airspeed_main(int argc, char *argv[]);

Expand Down Expand Up @@ -151,36 +153,48 @@ ms5525_airspeed_main(int argc, char *argv[])
{
uint8_t i2c_bus = PX4_I2C_BUS_DEFAULT;

for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) {
if (argc > i + 1) {
i2c_bus = atoi(argv[i + 1]);
}
int myoptind = 1;
int ch;
const char *myoptarg = nullptr;

while ((ch = px4_getopt(argc, argv, "b:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'b':
i2c_bus = atoi(myoptarg);
break;

default:
ms5525_airspeed_usage();
return 0;
}
}

if (myoptind >= argc) {
ms5525_airspeed_usage();
return -1;
}

/*
* Start/load the driver.
*/
if (!strcmp(argv[1], "start")) {
if (!strcmp(argv[myoptind], "start")) {
return ms5525_airspeed::start(i2c_bus);
}

/*
* Stop the driver
*/
if (!strcmp(argv[1], "stop")) {
if (!strcmp(argv[myoptind], "stop")) {
return ms5525_airspeed::stop();
}

/*
* Reset the driver.
*/
if (!strcmp(argv[1], "reset")) {
if (!strcmp(argv[myoptind], "reset")) {
return ms5525_airspeed::reset();
}

ms5525_airspeed_usage();

return PX4_OK;
return 0;
}
Loading