lps22hb: add argc check and use px4_getopt

This commit is contained in:
Beat Küng
2018-06-04 14:02:46 +02:00
committed by Lorenz Meier
parent 22bc35c048
commit 7e7905acd1
2 changed files with 14 additions and 5 deletions
@@ -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;
+14 -4
View File
@@ -33,6 +33,8 @@
#include "LPS22HB.hpp"
#include <px4_getopt.h>
#include <cstring>
extern "C" __EXPORT int lps22hb_main(int argc, char *argv[]);
@@ -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;
while ((ch = getopt(argc, argv, "XIS:")) != EOF) {
enum LPS22HB_BUS busid = LPS22HB_BUS_ALL;
while ((ch = px4_getopt(argc, argv, "XIS:", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
#if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_HMC)
@@ -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.