From 76b9923e55fd615d0edf065085a4c14475304868 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 25 Oct 2019 23:47:22 +0300 Subject: libcamera: controls: Avoid exception in ControlInfoMap count() and find() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ControlInfoMap count() and find() methods use at() to lookup the control numerical ID in the idmap_. This causes an exception to be thrown if the ID doesn't exist in the map. Fix it by using the find() method instead in find(), and rely on idmap_.count() in count(). Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/controls.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 93ad2fc6..c23c1b88 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -491,7 +491,12 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const */ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const { - return count(idmap_.at(id)); + /* + * 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); } /** @@ -502,7 +507,11 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const */ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id) { - return find(idmap_.at(id)); + auto iter = idmap_.find(id); + if (iter == idmap_.end()) + return end(); + + return find(iter->second); } /** @@ -513,7 +522,11 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id) */ ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const { - return find(idmap_.at(id)); + auto iter = idmap_.find(id); + if (iter == idmap_.end()) + return end(); + + return find(iter->second); } /** -- cgit v1.2.1