[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [blktap2] fix two 'maybe uninitialized' variables



On gio, 2014-06-12 at 10:18 +0100, Ian Campbell wrote:
> On Wed, 2014-06-11 at 14:01 +0200, Dario Faggioli wrote:
> > for which gcc 4.9.0 complains about, like this:
> > 
> > block-qcow.c: In function âget_cluster_offsetâ:
> > block-qcow.c:431:3: error: âtmp_ptrâ may be used uninitialized in this 
> > function [-Werror=maybe-uninitialized]
> >    memcpy(tmp_ptr, l1_ptr, 4096);
> >    ^
> > block-qcow.c:606:7: error: âtmp_ptr2â may be used uninitialized in this 
> > function [-Werror=maybe-uninitialized]
> >    if (write(s->fd, tmp_ptr2, 4096) != 4096) {
> 
> You initialise both of these to NULL as they are defined, but the
> compiler has apparently found a path where these values can be used
> without subsequently being initialised, so you are passing NULL to
> memcpy/write, which can't be good.
> 
> If you've proved that the compiler is wrong/confused and this cannot
> happen please explain the how/why it is wrong here.
> 
Your are right, sorry for this. Being super-unfamiliar with that code, I
was sort of relying on the fact that it is correct, especially
considering the nature of the warning message.

However, I understand, and actually agree, that it really is a bad
practice to suppress warnings like this... Let me have a deeper look and
see if I can propose a better fix.

Thanks and Regards,
Dario

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.