{"id":1777,"url":"https://patchwork.libcamera.org/api/patches/1777/?format=json","web_url":"https://patchwork.libcamera.org/patch/1777/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190812110447.9411-1-laurent.pinchart@ideasonboard.com>","date":"2019-08-12T11:04:47","name":"[libcamera-devel] hal: Fix comparison of integers of different signs","commit_ref":"a6799dc5b9ded442152b3430e321d9b147b9d7fd","pull_url":null,"state":"accepted","archived":false,"hash":"b8b23e78322fa534508cb5f7daadccb8ee8a2968","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1777/mbox/","series":[{"id":454,"url":"https://patchwork.libcamera.org/api/series/454/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=454","date":"2019-08-12T11:04:47","name":"[libcamera-devel] hal: Fix comparison of integers of different signs","version":1,"mbox":"https://patchwork.libcamera.org/series/454/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1777/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1777/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 50F0A61582\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2019 13:04:56 +0200 (CEST)","from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9DED6327;\n\tMon, 12 Aug 2019 13:04:55 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565607895;\n\tbh=Mhe5+7DC1C90jkLlXLAryzfc1zSp+uRdeDq/Q3WNPy4=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=JvO8XU3IQEI1LcbyRC/HdOKnNHPj0eGkAL90Kbi+Vkw4mdQ+0ViFjMbd5WqLVTXC3\n\thOCccJW4tt1kCLf6InMgbxV74Pd0Dnb614nM+yYxhzzWzaVEsx7bQF9jkGhxFfQuz5\n\tCiqlkfGMPPkeWb28TAWgymyH2Ec4hNLn8o0AShvk=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] hal: Fix comparison of integers of\n\tdifferent signs","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 12 Aug 2019 11:04:56 -0000"},"content":"The CameraHalManager::getCameraInfo() validates the camera id it\nreceives from the camera service, and in doing so compares it with an\nunsigned integer, generating a compiler error:\n\nsrc/android/camera_hal_manager.cpp:121:9: error: comparison of integers of different signs: 'int' and 'unsigned int' [-Werror,-Wsign-compare]\n        if (id >= numCameras() || id < 0) {\n            ~~ ^  ~~~~~~~~~~~~\n\nFix this by turning the id into an unsigned int, as camera ids can't be\nnegative. If a negative id is received from the camera service it will\nbe converted to a large unsigned integer that will fail the comparison\nwith numCameras().\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/camera_hal_manager.cpp | 4 ++--\n src/android/camera_hal_manager.h   | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)","diff":"diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp\nindex 08c759dfd8a1..1e66f63240da 100644\n--- a/src/android/camera_hal_manager.cpp\n+++ b/src/android/camera_hal_manager.cpp\n@@ -113,12 +113,12 @@ unsigned int CameraHalManager::numCameras() const\n \treturn cameraManager_->cameras().size();\n }\n \n-int CameraHalManager::getCameraInfo(int id, struct camera_info *info)\n+int CameraHalManager::getCameraInfo(unsigned int id, struct camera_info *info)\n {\n \tif (!info)\n \t\treturn -EINVAL;\n \n-\tif (id >= numCameras() || id < 0) {\n+\tif (id >= numCameras()) {\n \t\tLOG(HAL, Error) << \"Invalid camera id '\" << id << \"'\";\n \t\treturn -EINVAL;\n \t}\ndiff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h\nindex 8004aaf660f5..8228623aba90 100644\n--- a/src/android/camera_hal_manager.h\n+++ b/src/android/camera_hal_manager.h\n@@ -30,7 +30,7 @@ public:\n \tint close(CameraProxy *proxy);\n \n \tunsigned int numCameras() const;\n-\tint getCameraInfo(int id, struct camera_info *info);\n+\tint getCameraInfo(unsigned int id, struct camera_info *info);\n \n private:\n \tvoid run() override;\n","prefixes":["libcamera-devel"]}