From patchwork Tue Jan 28 12:13:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22655 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E5B88BD87C for ; Tue, 28 Jan 2025 12:14:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0D2146855D; Tue, 28 Jan 2025 13:14:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="ZfuvIDCN"; dkim-atps=neutral Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3466E68546 for ; Tue, 28 Jan 2025 13:14:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1738066441; x=1738325641; bh=u82KG5fEujZZMu1oSRNExKevwMuypiqiDteWz6iu2ms=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=ZfuvIDCNulDoSvfGU029gcZDNFJWASV7AVyo8rSANPuns3rke3I5tKbrrel5oPnz/ xIp3hkzz7peWYE27/DWEBpTT358w8b5cnQzyrlzXvY84VfsGP/IteVa7xEDs5FdfUq McuHyAc6E+czcyh0rJR97C1FBdaIjBisCSlVPc90OE0pbxZwVH+FPusuFgKCmy7fXn FhhsSL9w83mTbHQT6dwpLJjAWA2/f3El+Z+AS9tXniTQaGxgKtzDa3tKEWScOo+INg Jje1CvNlWkyQoWkVEME3QiOK7OPDHxga5X52upbjgfdVCPnIg3qjowepgjvCLQkWyp CCbOUdqAuqJkg== Date: Tue, 28 Jan 2025 12:13:55 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1] libcamera: controls: ControlInfo: Ensure types match Message-ID: <20250128121352.494582-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 1c702f71310bc5ca39656b4f24601235a73ac359 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- 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 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); + } } /**