diff options
author | Barnabás Pőcze <barnabas.pocze@ideasonboard.com> | 2025-04-02 13:37:39 +0200 |
---|---|---|
committer | Barnabás Pőcze <barnabas.pocze@ideasonboard.com> | 2025-05-22 11:22:34 +0200 |
commit | efdbe3969841e342c30dfdced38b6ad9ad55dccf (patch) | |
tree | bb86c091f5cf2efcbfc125861383ae7a87bbb929 /src | |
parent | 969df3db3195b43883b6a200bd022ee6c9928042 (diff) |
libcamera: controls: Fix `ControlInfoMap::count(unsigned int)`
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 <barnabas.pocze@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/controls.cpp | 10 |
1 files changed, 1 insertions, 9 deletions
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(); } /** |