From patchwork Mon Aug 12 11:04:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1777 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 50F0A61582 for ; Mon, 12 Aug 2019 13:04:56 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9DED6327; Mon, 12 Aug 2019 13:04:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1565607895; bh=Mhe5+7DC1C90jkLlXLAryzfc1zSp+uRdeDq/Q3WNPy4=; h=From:To:Cc:Subject:Date:From; b=JvO8XU3IQEI1LcbyRC/HdOKnNHPj0eGkAL90Kbi+Vkw4mdQ+0ViFjMbd5WqLVTXC3 hOCccJW4tt1kCLf6InMgbxV74Pd0Dnb614nM+yYxhzzWzaVEsx7bQF9jkGhxFfQuz5 CiqlkfGMPPkeWb28TAWgymyH2Ec4hNLn8o0AShvk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 12 Aug 2019 14:04:47 +0300 Message-Id: <20190812110447.9411-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] hal: Fix comparison of integers of different signs 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, 12 Aug 2019 11:04:56 -0000 The CameraHalManager::getCameraInfo() validates the camera id it receives from the camera service, and in doing so compares it with an unsigned integer, generating a compiler error: src/android/camera_hal_manager.cpp:121:9: error: comparison of integers of different signs: 'int' and 'unsigned int' [-Werror,-Wsign-compare] if (id >= numCameras() || id < 0) { ~~ ^ ~~~~~~~~~~~~ Fix this by turning the id into an unsigned int, as camera ids can't be negative. If a negative id is received from the camera service it will be converted to a large unsigned integer that will fail the comparison with numCameras(). Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/android/camera_hal_manager.cpp | 4 ++-- src/android/camera_hal_manager.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 08c759dfd8a1..1e66f63240da 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -113,12 +113,12 @@ unsigned int CameraHalManager::numCameras() const return cameraManager_->cameras().size(); } -int CameraHalManager::getCameraInfo(int id, struct camera_info *info) +int CameraHalManager::getCameraInfo(unsigned int id, struct camera_info *info) { if (!info) return -EINVAL; - if (id >= numCameras() || id < 0) { + if (id >= numCameras()) { LOG(HAL, Error) << "Invalid camera id '" << id << "'"; return -EINVAL; } diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 8004aaf660f5..8228623aba90 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -30,7 +30,7 @@ public: int close(CameraProxy *proxy); unsigned int numCameras() const; - int getCameraInfo(int id, struct camera_info *info); + int getCameraInfo(unsigned int id, struct camera_info *info); private: void run() override;