[libcamera-devel] libcamera: media_device: error: ‘ifaceId’ may be used uninitialised in this function

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Mar 19 11:11:13 CET 2019


Hello,

On Tue, Mar 19, 2019 at 11:00:21AM +0100, Jacopo Mondi wrote:
> On Tue, Mar 19, 2019 at 09:42:31AM +0000, Kieran Bingham wrote:
> > Hi Jacopo,
> >
> > I'm integrating libcamera into buildroot, and I've hit the following:
> >
> > Compiling libcamera on aarch64 currently fails with the following
> > warning treated as an error:
> 
> Thanks for reporting this.
> 
> > [12/87] Compiling C++ object
> > 'src/libcamera/4ab8042@@camera at sha/media_device.cpp.o'.
> > FAILED: src/libcamera/4ab8042@@camera at sha/media_device.cpp.o
> > /home/linuxembedded/iob/libcamera/buildroot/libcamera/arm64/host/bin/aarch64-linux-gnu-g++
> > -Isrc/libcamera/4ab8042@@camera at sha -Isrc/libcamera -I../src/libcamera
> > -Iinclude -I../include -I../src/libcamera/include
> > -I/home/linuxembedded/iob/libcamera/buildroot/libcamera/arm64/host/usr/bin/../aarch64-buildroot-linux-gnu/sysroot/usr/include
> > -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall
> > -Winvalid-pch -Wnon-virtual-dtor -Wextra -Werror -std=c++11 -O3
> > -Wno-unused-parameter -fPIC -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
> > -D_FILE_OFFSET_BITS=64 -Os -MD -MQ
> > 'src/libcamera/4ab8042@@camera at sha/media_device.cpp.o' -MF
> > 'src/libcamera/4ab8042@@camera at sha/media_device.cpp.o.d' -o
> > 'src/libcamera/4ab8042@@camera at sha/media_device.cpp.o' -c
> > ../src/libcamera/media_device.cpp
> > ../src/libcamera/media_device.cpp: In member function
> > ‘media_v2_interface* libcamera::MediaDevice::findInterface(const
> > media_v2_topology&, unsigned int)’:
> > ../src/libcamera/media_device.cpp:540:3: error: ‘ifaceId’ may be used
> > uninitialised in this function [-Werror=maybe-uninitialized]
> >    if (ifaces[i].id == ifaceId)
> >    ^~
> > cc1plus: all warnings being treated as errors
> > [20/87] Compiling C++ object
> > 'src/libcamera/4ab8042@@camera at sha/pipeline_uvcvideo.cpp.o'.
> > ninja: build stopped: subcommand failed.
> >
> >
> > I've hacked in a
> >
> > -unsigned int ifaceId;
> > +unsigned int ifaceId = 0;
> >
> > for the moment, but could you take a look at this please and see what
> > the correct resolution would be? (perhaps it is to just initialise to 0).
> 
> I think it's fine to initialize it to 0 just to silence the compiler.
> 
> The code is correct afaict: if ifaceId does not get initalized, we
> exit from the function before hitting line 540, which the compiler
> complains about.
> 
> If you're willing to send a patch to intialize ifaceId, please have
> mine:
> 
> Acked-by: Jacopo Mondi <jacopo at jmondi.org>

Assuming ifaceId == 0 isn't a valid ID (that needs to be
double-checked), you could also the replace the check after the loop
with

	if (ifaceId == 0)
		return nullptr;

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list