]> xenbits.xensource.com Git - xen.git/commitdiff
blktap2: Fix two 'maybe uninitialized' variables
authorDario Faggioli <dario.faggioli@citrix.com>
Fri, 20 Jun 2014 14:09:00 +0000 (16:09 +0200)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Wed, 2 Jul 2014 14:38:40 +0000 (15:38 +0100)
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) {
       ^
cc1: all warnings being treated as errors
/home/dario/Sources/xen/xen/xen.git/tools/blktap2/drivers/../../../tools/Rules.mk:89:
 recipe for target 'block-qcow.o' failed
make[5]: *** [block-qcow.o] Error 1

The proper behavior is to return upon allocation failure.
About what to return, 0 seems the best option, looking
at both the function and the call sites.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
(cherry picked from commit 345e44a85d71a1a910385f33c7f1ba3683026d18)
(cherry picked from commit 5e39eb05aa2a6d9bfa6c3b3e299b071422498625)
(cherry picked from commit c591613f8c629f18a521269d67240d532f2c27d1)

tools/blktap2/drivers/block-qcow.c

index d5053d41748bec9b7e43488e64b550f192fe77f7..b45bcaa077a29edbc4367ef9742e5bee1a8e69ec 100644 (file)
@@ -427,6 +427,7 @@ static uint64_t get_cluster_offset(struct tdqcow_state *s,
 
                if (posix_memalign((void **)&tmp_ptr, 4096, 4096) != 0) {
                        DPRINTF("ERROR allocating memory for L1 table\n");
+                        return 0;
                }
                memcpy(tmp_ptr, l1_ptr, 4096);
 
@@ -600,6 +601,7 @@ found:
                
                if (posix_memalign((void **)&tmp_ptr2, 4096, 4096) != 0) {
                        DPRINTF("ERROR allocating memory for L1 table\n");
+                        return 0;
                }
                memcpy(tmp_ptr2, l2_ptr, 4096);
                lseek(s->fd, l2_offset + (l2_sector << 12), SEEK_SET);