[PATCH btbridge v4 1/6] Initialise variable to avoid using it uninitialised

Cyril Bur cyril.bur at au1.ibm.com
Thu May 19 15:44:50 AEST 2016


On Thu, 19 May 2016 12:40:49 +0930
Andrew Jeffery <andrew at aj.id.au> wrote:

> Hi Cyril,
> 
> On Tue, 2016-05-03 at 20:10 -0500, OpenBMC Patches wrote:
> > From: Cyril Bur <cyril.bur at au1.ibm.com>
> > 
> > Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
> > ---
> >  btbridged.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/btbridged.c b/btbridged.c
> > index fe692bb..3e261a9 100644
> > --- a/btbridged.c
> > +++ b/btbridged.c
> > @@ -489,7 +489,7 @@ static int dispatch_sd_bus(struct btbridged_context *context)
> >  static int dispatch_bt(struct btbridged_context *context)
> >  {
> >  	int err = 0;
> > -	int r;
> > +	int r = 0;
> >  
> >  	assert(context);
> >    
> 
> Building with this patch and native GCC* gives errors:
> 
>     $ KERNEL_HEADERS=../../linux/ast2400/include/uapi/ make
>     cc  -Wall -O2 -g -I../../linux/ast2400/include/uapi/    btbridged.c  -lsystemd -o btbridged
>     btbridged.c: In function ‘main’:
>     btbridged.c:590:6: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>        if (r < 0)
>           ^
>     btbridged.c:342:6: note: ‘r’ was declared here
>       int r, len;
>           ^
> 
> That's weird, because the note isn't relevant to the function of line
> that generated the warning. However, the 'r' defined in bt_host_write()
> suffers the same initialisation issue. Initialising it gives me a build
> with no warnings so maybe it's worth doing that here also?
> 

Yeah, GCC seems to be getting a bit confused. I'm usually not in favour of
putting in stuff to shut the warnings up but these are just so odd that I'm at
a loss.

Your suggestion works, lets just do that and forget about it.

Thanks

> Otherwise,
> 
> Acked-by: Andrew Jeffery <andrew at aj.id.au>
> 
> Cheers,
> 
> Andrew
> 
> * $ gcc --version
> gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413



More information about the openbmc mailing list