From patchwork Mon Jun 10 11:49:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 1379 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A344B63347 for ; Mon, 10 Jun 2019 13:50:17 +0200 (CEST) X-Halon-ID: d37b02c2-8b75-11e9-8601-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id d37b02c2-8b75-11e9-8601-0050569116f7; Mon, 10 Jun 2019 13:49:42 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 10 Jun 2019 13:49:36 +0200 Message-Id: <20190610114936.30175-1-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] cam: Fix cam --help crash X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jun 2019 11:50:17 -0000 The cam utility do not terminate correctly if invoked with only --help. It prints the help information and then segfaults as the application is not terminated correctly. Fix this by moving the return code check of the option parsing to main(). Reported-by: Emmanuel Arias Suggested-by: Jacopo Mondi Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/cam/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index dbf04917bcc5aa38..f03a9faf87fac865 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -61,7 +61,7 @@ int CamApp::init(int argc, char **argv) ret = parseOptions(argc, argv); if (ret < 0) - return ret == -EINTR ? 0 : ret; + return ret; cm_ = CameraManager::instance(); @@ -193,9 +193,11 @@ void signalHandler(int signal) int main(int argc, char **argv) { CamApp app; + int ret; - if (app.init(argc, argv)) - return EXIT_FAILURE; + ret = app.init(argc, argv); + if (ret) + return ret == -EINTR ? 0 : EXIT_FAILURE; struct sigaction sa = {}; sa.sa_handler = &signalHandler;