From 490ccc0076dde2e804d25be339ea02e5869d0ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 4 Jun 2018 14:26:45 +0200 Subject: [PATCH] sf1xx: add argc check --- src/drivers/distance_sensor/sf1xx/sf1xx.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/drivers/distance_sensor/sf1xx/sf1xx.cpp b/src/drivers/distance_sensor/sf1xx/sf1xx.cpp index e4156c3c05..1c1fd1eeac 100644 --- a/src/drivers/distance_sensor/sf1xx/sf1xx.cpp +++ b/src/drivers/distance_sensor/sf1xx/sf1xx.cpp @@ -816,25 +816,27 @@ info() int sf1xx_main(int argc, char *argv[]) { - // check for optional arguments int ch; int myoptind = 1; const char *myoptarg = nullptr; uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING; - while ((ch = px4_getopt(argc, argv, "R:", &myoptind, &myoptarg)) != EOF) { switch (ch) { case 'R': rotation = (uint8_t)atoi(myoptarg); - PX4_INFO("Setting distance sensor orientation to %d", (int)rotation); break; default: PX4_WARN("Unknown option!"); + return -1; } } + if (myoptind >= argc) { + goto out_error; + } + /* * Start/load the driver. */ @@ -870,6 +872,7 @@ sf1xx_main(int argc, char *argv[]) sf1xx::info(); } +out_error: PX4_ERR("unrecognized command, try 'start', 'test', 'reset' or 'info'"); - return PX4_ERROR; + return -1; }