[PATCH v1] libcamera: controls: Fix `ControlInfoMap::count(unsigned int)`
Paul Elder
paul.elder at ideasonboard.com
Tue May 13 14:45:54 CEST 2025
Hi Barnabás,
Thanks for the patch.
Quoting Barnabás Pőcze (2025-04-02 13:50:10)
> 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.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze at ideasonboard.com>
Looks good to me.
Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
> src/libcamera/controls.cpp | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 70f6f6092..98fa7583d 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();
> }
>
> /**
> --
> 2.49.0
>
More information about the libcamera-devel
mailing list