From 5771125bfa4ae6c51a214d42933c393352395a89 Mon Sep 17 00:00:00 2001 From: Marco Felsch Date: Fri, 2 Sep 2022 16:11:36 +0200 Subject: qcam: viewfinder_gl: Fix maybe-uninitialized warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Bug: https://bugs.libcamera.org/show_bug.cgi?id=143 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: Umang Jain --- src/qcam/viewfinder_gl.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp index e2aa2470..38ddad58 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; -- cgit v1.2.1