From efdbe3969841e342c30dfdced38b6ad9ad55dccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 2 Apr 2025 13:37:39 +0200 Subject: libcamera: controls: Fix `ControlInfoMap::count(unsigned int)` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two overloads of `find()` and `at()` have the same behaviour regardless of the argument type: `unsigned int` or `const ControlId *`. However, `count()` is not so because `count(unsigned int)` only checks the `ControlIdMap`, and it does not check if the given id is actually present in the map storing the `ControlInfo` objects. So `count()` returns 1 for every control id that is present in the associated `ControlIdMap` regardless of whether there is an actual entry for the `ControlId` associated with the given numeric id. Fix that by simply using `find()` to determine the return value. Fixes: 76b9923e55fd61 ("libcamera: controls: Avoid exception in ControlInfoMap count() and find()") Signed-off-by: Barnabás Pőcze Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder --- src/libcamera/controls.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src') diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 70f6f609..98fa7583 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -857,15 +857,7 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const */ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const { - if (!idmap_) - return 0; - - /* - * The ControlInfoMap and its idmap have a 1:1 mapping between their - * entries, we can thus just count the matching entries in idmap to - * avoid an additional lookup. - */ - return idmap_->count(id); + return find(id) != end(); } /** -- cgit v1.2.1