From patchwork Sat Sep 3 00:35:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17284 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 1ED05C3272 for ; Sat, 3 Sep 2022 00:35:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5B3836201D; Sat, 3 Sep 2022 02:35:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662165328; bh=eGvw1YxkJUCUs5BoknHKVfrqSrghVz9sEpI9PONZsHM=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=HQAR0Wb7EZUlEXcndRoeC0qTIV5bJ2eapCH2efdkmEzrEKd1idHWMP3qMJyFK1Gqp MTXzYx6Reuum3g2STdbpwe62l0/svjb9+9EdQcAcXCCW9hV5PIohX4k/uf0a2oVaJv H4vSB7awq1+ejslZcp3AwW1jkbo0tAJ3GVm/Yz4EjeyjPk44HUJ1c+gFqSbulkjWZ3 B3uJrHAhMvbcKuPWls6nbQRDn0lK7I7TABuAEsM5lFhd6i3z8fcVp9zShK9sn0riwm UBYCgd+/A/gGFV3ypSEgB6yF2cZfxDGQkjRMGiSfUU5jsYnn1DvApcJ58wMvbKupK9 1s6yZt0vSCNsw== 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 B6A2061FF2 for ; Sat, 3 Sep 2022 02:35:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hddYH04W"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 141416DD; Sat, 3 Sep 2022 02:35:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1662165326; bh=eGvw1YxkJUCUs5BoknHKVfrqSrghVz9sEpI9PONZsHM=; h=From:To:Cc:Subject:Date:From; b=hddYH04Wxv8gHgHXPxfxxGgHWnXKFCugiqRPMynueIDp6tixxfgiUK99SRgxpjyXa r0nIsqsaT3DnkSU3YdeIAuTw5PJMN7Mxgnm93COm8ZuHnt9t+Gxu9P3Lw4IDnjyVlA cywWoJpuOzFIQsV6/ZqB5z/FL8PFevoewJ7WXfVA= To: libcamera-devel@lists.libcamera.org Date: Sat, 3 Sep 2022 03:35:13 +0300 Message-Id: <20220903003513.2516-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] qcam: viewfinder_gl: Fix maybe-uninitialized warnings 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: mfe@pengutronix.de, drebert@web.de Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Marco Felsch Commit 251f0534b74b ("qcam: viewfinder_gl: Take color space into account for YUV rendering") introduced maybe-uninitialized warnings with gcc 11 and 12 when compiling with -O3. Both compilers warn that ../../src/qcam/viewfinder_gl.cpp: In member function ‘void ViewFinderGL::selectColorSpace(const libcamera::ColorSpace&)’: ../../src/qcam/viewfinder_gl.cpp:392:21: error: ‘offset’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 391 | fragmentShaderDefines_.append(QString("#define YUV2RGB_Y_OFFSET %1") | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 392 | .arg(offset, 0, 'f', 1)); | ~~~~^~~~~~~~~~~~~~~~~~~ Additionally, gcc 12 warns that ../../src/qcam/viewfinder_gl.cpp: In member function ‘void ViewFinderGL::selectColorSpace(const libcamera::ColorSpace&)’: ../../src/qcam/viewfinder_gl.cpp:379:36: error: ‘yuv2rgb’ may be used uninitialized [-Werror=maybe-uninitialized] 379 | yuv2rgb[i] *= 255.0 / 219.0; ../../src/qcam/viewfinder_gl.cpp:330:31: note: ‘yuv2rgb’ declared here 330 | std::array yuv2rgb; | While this should never happen here, the compiler isn't necessarily wrong, as C++17 allows initializing a scoped enum from an integer using direct-list-initialization, even if the integer value doesn't match any of the enumerators for the scoped enum ([1]). Whether this is valid or borderline paranoia from gcc may be debatable, but in any case it can't be classified as blatantly wrong. Fix the warnings by adding default cases to the switch statements in ViewFinderGL::selectColorSpace(). Which case is selected as the default doesn't matter, as this is not meant to happen. [1] https://en.cppreference.com/w/cpp/language/enum#enum_relaxed_init_cpp17 Fixes: 251f0534b74b ("qcam: viewfinder_gl: Take color space into account for YUV rendering") Signed-off-by: Marco Felsch Reviewed-by: Laurent Pinchart Rewrote commit message, added a default case for the encoding switch. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Umang Jain --- src/qcam/viewfinder_gl.cpp | 2 ++ 1 file changed, 2 insertions(+) base-commit: 251f0534b74bcb46c777aa0df34b1b4142b664f5 diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index e2aa24703ff0..38ddad58e09e 100644 --- a/src/qcam/viewfinder_gl.cpp +++ b/src/qcam/viewfinder_gl.cpp @@ -332,6 +332,7 @@ void ViewFinderGL::selectColorSpace(const libcamera::ColorSpace &colorSpace) /* OpenGL stores arrays in column-major order. */ switch (colorSpace.ycbcrEncoding) { case libcamera::ColorSpace::YcbcrEncoding::None: + default: yuv2rgb = { 1.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, @@ -368,6 +369,7 @@ void ViewFinderGL::selectColorSpace(const libcamera::ColorSpace &colorSpace) switch (colorSpace.range) { case libcamera::ColorSpace::Range::Full: + default: offset = 0.0; break;