[{"id":33473,"web_url":"https://patchwork.libcamera.org/comment/33473/","msgid":"<85a5aah088.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-02-25T08:55:51","subject":"Re: [PATCH 1/2] libipa: awb: Fix non-virtual destructor warning in\n\tAwbStats","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Hi Laurent,\n\nthank you for the fix.\n\nLaurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> The AwbStats structure has virtual functions but a publicly accessible\n> non-virtual destructors. This can cause undefined behaviour if deleting\n> a derived class instance through a pointer to the base AwbStats class.\n>\n> The problem is theoretical only as no code in libcamera is expected to\n> perform such deletion, but compilers can't know that and will emit a\n> warning if the -Wnon-virtual-dtor option is enabled.\n>\n> Fixing this can be done by declaring a virtual public destructor in the\n> AwbStats class. A more efficient alternative is to declare a protected\n> non-virtual destructor, ensuring that instances can't be deleted through\n> a pointer to the base class. Do so, and mark the derived RkISP1AwbStats\n> as final to avoid the same warning.\n>\n> Fixes: 6f663990a0f7 (\"libipa: Add AWB algorithm base class\")\n> Reported-by: Milan Zamazal <mzamazal@redhat.com>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI can confirm it builds fine with this in my environment (CentOS 9).\n\n> ---\n>  src/ipa/libipa/awb.h              | 3 +++\n>  src/ipa/rkisp1/algorithms/awb.cpp | 2 +-\n>  2 files changed, 4 insertions(+), 1 deletion(-)\n>\n> diff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h\n> index a86581adf43e..4bab7a451ce5 100644\n> --- a/src/ipa/libipa/awb.h\n> +++ b/src/ipa/libipa/awb.h\n> @@ -27,6 +27,9 @@ struct AwbResult {\n>  struct AwbStats {\n>  \tvirtual double computeColourError(const RGB<double> &gains) const = 0;\n>  \tvirtual RGB<double> rgbMeans() const = 0;\n> +\n> +protected:\n> +\t~AwbStats() = default;\n>  };\n>  \n>  class AwbAlgorithm\n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index 6f9d454eb88f..eafe93081bb1 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -42,7 +42,7 @@ constexpr int32_t kDefaultColourTemperature = 5000;\n>  /* Minimum mean value below which AWB can't operate. */\n>  constexpr double kMeanMinThreshold = 2.0;\n>  \n> -class RkISP1AwbStats : public AwbStats\n> +class RkISP1AwbStats final : public AwbStats\n>  {\n>  public:\n>  \tRkISP1AwbStats(const RGB<double> &rgbMeans)","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 85011BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Feb 2025 08:56:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 86E2968711;\n\tTue, 25 Feb 2025 09:56:01 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 63C5068697\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Feb 2025 09:55:59 +0100 (CET)","from mail-wm1-f72.google.com (mail-wm1-f72.google.com\n\t[209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-519-hMKndv0YP-aU4kRm_w9oVw-1; Tue, 25 Feb 2025 03:55:56 -0500","by mail-wm1-f72.google.com with SMTP id\n\t5b1f17b1804b1-4399c5ba9e4so29370015e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Feb 2025 00:55:56 -0800 (PST)","from mzamazal-thinkpadp1gen7.tpbc.csb (nat-pool-brq-t.redhat.com.\n\t[213.175.37.10]) by smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-43ab1532f0asm18150415e9.4.2025.02.25.00.55.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 25 Feb 2025 00:55:52 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"dqPZ6bMa\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1740473758;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=d/sU+CTrfykdiNJaYMJXjl9zdVfRWrSp1zA56sDGxFo=;\n\tb=dqPZ6bMajDTtULHvSEJ9K17tNAYJqqj8CdYyB7ekz5igFNOvNJHX7NG/JiRp2eea3U11Uj\n\t9o8Fw/1LRUFwfPcyvYPSagzmNkQD6dpA9pttxj18P0kVOPs+osJTryKiD+4NmnCtidOemE\n\tIgj0+C9xoxKrm5BmM5pJRaun4DrV9Wo=","X-MC-Unique":"hMKndv0YP-aU4kRm_w9oVw-1","X-Mimecast-MFC-AGG-ID":"hMKndv0YP-aU4kRm_w9oVw_1740473755","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1740473754; x=1741078554;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=d/sU+CTrfykdiNJaYMJXjl9zdVfRWrSp1zA56sDGxFo=;\n\tb=f4kPk1yYEfippfB1MnUCl0DJO9gPRhhY2OzfsyUSrzSpqSZAnmVvpEw/SAFjIgAOOJ\n\tEJVxMHNR991VV1DLDRtgEbngHt7pxRtWDdnmcxTrDactSftsUtaCE3B1I2FFsRLilLfw\n\twW9DOLOZzHAzHbsRYbyBssOae1ntwPDHmFCKfKEf08/nbNOgBYzFlLkChNj4TtbYmR9S\n\tabtFt2QfOW6DiUob5a861WrPj/ls5bpFhR14YsGEpKWk7amCs8IMV5/guYGDCfH2Mh3O\n\tRzrgmdyVxa9oTWRBfy8wPFCmGxop1J6XZFVQ4TkFRbY9pWI/krYDa2LfusuvVqyRBQUx\n\tKAhg==","X-Gm-Message-State":"AOJu0Yxn95RQ12lUbysawZ3TTTcbAFqKx7iVlqJl/jnNIQybQ6MiiQzg\n\thaCO8tj6d3hM47Gu1RMeuU7PUpmlWwCPoZtt8eP/As+PFUn33phvKMQEfKawirMHXVmEMyUrmot\n\t5rl/2kMnm2mg2GdkX2/2zIb6YEqVjNDhn8r5Opzrj1ke10dZ9A7MmGXtu2jw2eE0soEEiZe/dV+\n\tRYKmA=","X-Gm-Gg":"ASbGncsBuBcGowK7OAsqlvlMhV7DBelnMDPg21Erwbjmb+bw3U6/U8pDr1fuZI+/QEp\n\tkKzfX7532slpS92+lpLveZNXMe9LbWTyZKFtMAUzcP8gcLUhasuSHpp9J3wlhkg1VXPZ5IHDfEr\n\tqY/bybCiipI6G7E+2RbgWIFjwcVysU9y2i1ZdaurHbH5RJjkUtkQPLKfaPelYDLpdk2Llw/h10i\n\t/wDdqfiJeFAJfg53KHEmKvZkdwCLC9IdV0S0GQ20SRFFXwVRJ9f5wWJm0w3AbhCHpKzvg2+yF68\n\td3awKELGnyfWj8vNn//1EhJlmfYOwJqFkXHi1UhHaGdYnl+xGMM3AfNABct89puZqsE=","X-Received":["by 2002:a05:600c:468e:b0:439:9828:c44b with SMTP id\n\t5b1f17b1804b1-43ab0f3ccddmr22896975e9.14.1740473754591; \n\tTue, 25 Feb 2025 00:55:54 -0800 (PST)","by 2002:a05:600c:468e:b0:439:9828:c44b with SMTP id\n\t5b1f17b1804b1-43ab0f3ccddmr22896775e9.14.1740473754220; \n\tTue, 25 Feb 2025 00:55:54 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IE4iufAaA2WDxEl+yJ8W29qJhuOLk6k/p6E0mTV6SoOJ7wYyvnDzyerT3imx5S5TJHDzICDaA==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,  Stefan Klug\n\t<stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH 1/2] libipa: awb: Fix non-virtual destructor warning in\n\tAwbStats","In-Reply-To":"<20250224220438.21512-2-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Tue, 25 Feb 2025 00:04:37 +0200\")","References":"<20250224220438.21512-1-laurent.pinchart@ideasonboard.com>\n\t<20250224220438.21512-2-laurent.pinchart@ideasonboard.com>","Date":"Tue, 25 Feb 2025 09:55:51 +0100","Message-ID":"<85a5aah088.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"omlrcd789JEdY1iWp_Vq15MpNmjHKi0d15IStDAr6_g_1740473755","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":33480,"web_url":"https://patchwork.libcamera.org/comment/33480/","msgid":"<fqvwvhy7k4vmnobzkk3oqr3d6x4wtd57o7ieab4cuwzhwbmhvm@uo4vx57hbczx>","date":"2025-02-25T22:10:22","subject":"Re: [PATCH 1/2] libipa: awb: Fix non-virtual destructor warning in\n\tAwbStats","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Laurent,\n\nThanks for fixing that.\n\nOn Tue, Feb 25, 2025 at 12:04:37AM +0200, Laurent Pinchart wrote:\n> The AwbStats structure has virtual functions but a publicly accessible\n> non-virtual destructors. This can cause undefined behaviour if deleting\n> a derived class instance through a pointer to the base AwbStats class.\n> \n> The problem is theoretical only as no code in libcamera is expected to\n> perform such deletion, but compilers can't know that and will emit a\n> warning if the -Wnon-virtual-dtor option is enabled.\n> \n> Fixing this can be done by declaring a virtual public destructor in the\n> AwbStats class. A more efficient alternative is to declare a protected\n> non-virtual destructor, ensuring that instances can't be deleted through\n> a pointer to the base class. Do so, and mark the derived RkISP1AwbStats\n> as final to avoid the same warning.\n> \n> Fixes: 6f663990a0f7 (\"libipa: Add AWB algorithm base class\")\n> Reported-by: Milan Zamazal <mzamazal@redhat.com>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> \n\nRegards,\nStefan\n\n> ---\n>  src/ipa/libipa/awb.h              | 3 +++\n>  src/ipa/rkisp1/algorithms/awb.cpp | 2 +-\n>  2 files changed, 4 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h\n> index a86581adf43e..4bab7a451ce5 100644\n> --- a/src/ipa/libipa/awb.h\n> +++ b/src/ipa/libipa/awb.h\n> @@ -27,6 +27,9 @@ struct AwbResult {\n>  struct AwbStats {\n>  \tvirtual double computeColourError(const RGB<double> &gains) const = 0;\n>  \tvirtual RGB<double> rgbMeans() const = 0;\n> +\n> +protected:\n> +\t~AwbStats() = default;\n>  };\n>  \n>  class AwbAlgorithm\n> diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\n> index 6f9d454eb88f..eafe93081bb1 100644\n> --- a/src/ipa/rkisp1/algorithms/awb.cpp\n> +++ b/src/ipa/rkisp1/algorithms/awb.cpp\n> @@ -42,7 +42,7 @@ constexpr int32_t kDefaultColourTemperature = 5000;\n>  /* Minimum mean value below which AWB can't operate. */\n>  constexpr double kMeanMinThreshold = 2.0;\n>  \n> -class RkISP1AwbStats : public AwbStats\n> +class RkISP1AwbStats final : public AwbStats\n>  {\n>  public:\n>  \tRkISP1AwbStats(const RGB<double> &rgbMeans)\n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5F3A3BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Feb 2025 22:10:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5C0CD6872C;\n\tTue, 25 Feb 2025 23:10:27 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 61360686D6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Feb 2025 23:10:25 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:20f2:ccd6:fd0b:f3d])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C841E73B;\n\tTue, 25 Feb 2025 23:08:57 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bCxWuHFE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1740521337;\n\tbh=BlN9/wJIARkYAt7mmWlE0pq9rHOUDHT25ttFwGOOzD8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=bCxWuHFE1gsny/JQLuhE/gDPiTWMXtfKKmTWmE4a4WTeXSkeUicefn0hGZPbcfMG7\n\tj4oqfrb7Qw4055ik5JjxBBR0B9S+wIBZbCe8t+gJc9XYt+4h5wjpXAvAXXkqJmm8Gn\n\t5f1V/ccRH4MMTO66gBtjNGH2F5hhR+OLpwNxcA4s=","Date":"Tue, 25 Feb 2025 23:10:22 +0100","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, Milan Zamazal <mzamazal@redhat.com>","Subject":"Re: [PATCH 1/2] libipa: awb: Fix non-virtual destructor warning in\n\tAwbStats","Message-ID":"<fqvwvhy7k4vmnobzkk3oqr3d6x4wtd57o7ieab4cuwzhwbmhvm@uo4vx57hbczx>","References":"<20250224220438.21512-1-laurent.pinchart@ideasonboard.com>\n\t<20250224220438.21512-2-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250224220438.21512-2-laurent.pinchart@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]