[libcamera-devel] [PATCH v2 2/2] test: controls: control_info_map: Test default constructor

Mattijs Korpershoek mkorpershoek at baylibre.com
Wed Apr 5 10:14:31 CEST 2023


ControlInfoMap can be default-constructed. In that case, some of its
members (like idmap_) can be a nullptr, and ControlInfoMap.find() will segfault.

Add a test with a default constructed ControlInfoMap to cover this.

Signed-off-by: Mattijs Korpershoek <mkorpershoek at baylibre.com>
---
 test/controls/control_info_map.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/test/controls/control_info_map.cpp b/test/controls/control_info_map.cpp
index db95945a1580..29b33515e48c 100644
--- a/test/controls/control_info_map.cpp
+++ b/test/controls/control_info_map.cpp
@@ -75,6 +75,13 @@ protected:
 			return TestFail;
 		}
 
+		/* Test looking up a control on a default-constructed infoMap */
+		const ControlInfoMap emptyInfoMap;
+		if (emptyInfoMap.find(12345) != emptyInfoMap.end()) {
+			cerr << "find() on empty ControlInfoMap failed" << endl;
+			return TestFail;
+		}
+
 		return TestPass;
 	}
 };

-- 
2.39.2



More information about the libcamera-devel mailing list