From patchwork Mon Feb 24 22:04:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 22853 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 9A5F3BF415 for ; Mon, 24 Feb 2025 22:05:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 41C7868715; Mon, 24 Feb 2025 23:05:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="R2UBwaxH"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4AA8961856 for ; Mon, 24 Feb 2025 23:05:00 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 561BC7EA; Mon, 24 Feb 2025 23:03:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1740434613; bh=qx9j7jLD3g7183ifumkfwGC3vlB8/dtEvKxWiPdysRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R2UBwaxHt7Xlu3VRgSoZ7Tch0MmRhy2z8b1GOsFPx7Thc6mHjSrgIuLTCryIXbNyH aJObqisxYxVtLCUzGmJo13hN38Amyo3U1byKAW07tKs4u/bTn7YSL299MnvUAhy2Fv Zb18QnVB2svD/TfftIRyzD1puRiWht9inTSypIpc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Milan Zamazal Subject: [PATCH 1/2] libipa: awb: Fix non-virtual destructor warning in AwbStats Date: Tue, 25 Feb 2025 00:04:37 +0200 Message-ID: <20250224220438.21512-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250224220438.21512-1-laurent.pinchart@ideasonboard.com> References: <20250224220438.21512-1-laurent.pinchart@ideasonboard.com> 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" The AwbStats structure has virtual functions but a publicly accessible non-virtual destructors. This can cause undefined behaviour if deleting a derived class instance through a pointer to the base AwbStats class. The problem is theoretical only as no code in libcamera is expected to perform such deletion, but compilers can't know that and will emit a warning if the -Wnon-virtual-dtor option is enabled. Fixing this can be done by declaring a virtual public destructor in the AwbStats class. A more efficient alternative is to declare a protected non-virtual destructor, ensuring that instances can't be deleted through a pointer to the base class. Do so, and mark the derived RkISP1AwbStats as final to avoid the same warning. Fixes: 6f663990a0f7 ("libipa: Add AWB algorithm base class") Reported-by: Milan Zamazal Signed-off-by: Laurent Pinchart Reviewed-by: Stefan Klug --- src/ipa/libipa/awb.h | 3 +++ src/ipa/rkisp1/algorithms/awb.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h index a86581adf43e..4bab7a451ce5 100644 --- a/src/ipa/libipa/awb.h +++ b/src/ipa/libipa/awb.h @@ -27,6 +27,9 @@ struct AwbResult { struct AwbStats { virtual double computeColourError(const RGB &gains) const = 0; virtual RGB rgbMeans() const = 0; + +protected: + ~AwbStats() = default; }; class AwbAlgorithm diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 6f9d454eb88f..eafe93081bb1 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -42,7 +42,7 @@ constexpr int32_t kDefaultColourTemperature = 5000; /* Minimum mean value below which AWB can't operate. */ constexpr double kMeanMinThreshold = 2.0; -class RkISP1AwbStats : public AwbStats +class RkISP1AwbStats final : public AwbStats { public: RkISP1AwbStats(const RGB &rgbMeans) From patchwork Mon Feb 24 22:04:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 22854 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 4AEC7BF415 for ; Mon, 24 Feb 2025 22:05:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AF3AD68719; Mon, 24 Feb 2025 23:05:06 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="iw9fHluk"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5AFF16870E for ; Mon, 24 Feb 2025 23:05:02 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9F9E482A; Mon, 24 Feb 2025 23:03:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1740434615; bh=tCrJlyp082j7WOX1a1l+duTfQIxi8EvqffXdAx0AoDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iw9fHluk4o1VVQ3lcd4tKJD79nLhOPBOWTOlenB4ET5KVrQf85ix7h0hFtGbrAvzj 9tm5rHoLcsfAJCPP8BlTuD1Ca0H48Z3mJIiKEARzUtk2qaMrFq+6tVR+h5Bqm0RwQt kVwQfI89bECcJieXBMxasOMEProm5Wk/4CIcIhZ8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Milan Zamazal Subject: [PATCH 2/2] meson: Enable the -Wnon-virtual-dtor compiler option Date: Tue, 25 Feb 2025 00:04:38 +0200 Message-ID: <20250224220438.21512-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250224220438.21512-1-laurent.pinchart@ideasonboard.com> References: <20250224220438.21512-1-laurent.pinchart@ideasonboard.com> 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" A base class with virtual functions and a non-virtual public destructor is prone to undefined behaviourif deleted from a pointer to the base. Enable the -Wnon-virtual-dtor warning to report those issues. Signed-off-by: Laurent Pinchart Reviewed-by: Milan Zamazal Reviewed-by: Stefan Klug --- meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 5270f626f2fb..f8d32dcf8d7a 100644 --- a/meson.build +++ b/meson.build @@ -110,7 +110,9 @@ common_arguments = [ ] c_arguments = [] -cpp_arguments = [] +cpp_arguments = [ + '-Wnon-virtual-dtor', +] cxx_stdlib = 'libstdc++'