[libcamera-devel] [PATCH 1/2] libcamera: pipeline: ipu3: Fix warning when compiled with optimization

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon May 31 04:07:44 CEST 2021


When compiling with optimization, gcc 9 and newer throw an unitialized
variable warning:

../../src/libcamera/pipeline/ipu3/imgu.cpp: In function ‘void libcamera::{anonymous}::calculateBDSHeight(libcamera::ImgUDevice::Pipe*, const libcamera::Size&, const libcamera::Size&, unsigned int, float)’:
../../src/libcamera/pipeline/ipu3/imgu.cpp:172:17: error: ‘bdsHeight’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  172 |    unsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);

Neither clang not gcc versions older than 9 complain. This seems to be
a false positive, work around it by initializing the bdsHeight variable
when declaring it.

Note that there are obvious errors in the code, with the second while ()
loop in the first part of calculateBDSHeight() modifying the bdsHeight
variable set by the first loop even if the second loop doesn't find a
suitable height, but that's out of scope for this fix.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/libcamera/pipeline/ipu3/imgu.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp
index 3e517ac67962..f3eaab648399 100644
--- a/src/libcamera/pipeline/ipu3/imgu.cpp
+++ b/src/libcamera/pipeline/ipu3/imgu.cpp
@@ -126,7 +126,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc
 	unsigned int minIFHeight = iif.height - IF_CROP_MAX_H;
 	unsigned int minBDSHeight = gdc.height + FILTER_H * 2;
 	unsigned int ifHeight;
-	float bdsHeight;
+	float bdsHeight = 0.0f;
 
 	if (!isSameRatio(pipe->input, gdc)) {
 		unsigned int foundIfHeight = 0;
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list