[RFC PATCH v1] libcamera: controls: ControlInfo: Ensure types match
Barnabás Pőcze
pobrn at protonmail.com
Tue Jan 28 13:13:55 CET 2025
It is expected that the min/max/default/etc. values in a `ControlInfo`
have the same type. So add assertions to check that.
Signed-off-by: Barnabás Pőcze <pobrn at protonmail.com>
---
src/libcamera/controls.cpp | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 70f6f6092..07f276b35 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -580,6 +580,19 @@ ControlId::ControlId(unsigned int id, const std::string &name,
* \brief The Control template type T
*/
+namespace {
+
+bool sameShape(const ControlValue &a, const ControlValue &b)
+{
+ /**
+ * \todo This is a best effort approach. Without the `ControlId`
+ * there is no way to check if the sizes of fixed size arrays match.
+ */
+ return a.type() == b.type() && a.isArray() == b.isArray();
+}
+
+}
+
/**
* \class ControlInfo
* \brief Describe the limits of valid values for a Control
@@ -601,6 +614,7 @@ ControlInfo::ControlInfo(const ControlValue &min,
const ControlValue &def)
: min_(min), max_(max), def_(def)
{
+ ASSERT(sameShape(min_, max_) && (def_.isNone() || sameShape(max_, def_)));
}
/**
@@ -616,13 +630,19 @@ ControlInfo::ControlInfo(const ControlValue &min,
ControlInfo::ControlInfo(Span<const ControlValue> values,
const ControlValue &def)
{
+ ASSERT(!values.empty());
+
min_ = values.front();
max_ = values.back();
def_ = !def.isNone() ? def : values.front();
+ ASSERT(sameShape(min_, max_) && sameShape(max_, def_));
+
values_.reserve(values.size());
- for (const ControlValue &value : values)
+ for (const ControlValue &value : values) {
+ ASSERT(sameShape(def_, value));
values_.push_back(value);
+ }
}
/**
--
2.48.1
More information about the libcamera-devel
mailing list