From: Dario Faggioli <dario.faggioli@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian.Jackson@citrix.com,
Thanos Makatos <thanos.makatos@citrix.com>,
Keir Fraser <keir@xen.org>,
Ian.Campbell@citrix.com, David Scott <Dave.Scott@eu.citrix.com>
Subject: [PATCH v2] blktap2: Fix two 'maybe uninitialized' variables
Date: Fri, 20 Jun 2014 16:09:00 +0200 [thread overview]
Message-ID: <20140620140854.19823.79938.stgit@Solace> (raw)
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>
---
Changes from v1:
* instead of just inizialize the variables to suppress the warning,
fix the issue by returning when the allocation fails.
I am resubmitting this as a proper patch, as Ian Campbell suggested,
as days have passed, and no one showed up suggesting that something
could be wrong with the patch. I still am no expert in blktap, but
I looked once more at the code, and this patch seems ok to me.
---
tools/blktap2/drivers/block-qcow.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/blktap2/drivers/block-qcow.c b/tools/blktap2/drivers/block-qcow.c
index d5053d4..b45bcaa 100644
--- a/tools/blktap2/drivers/block-qcow.c
+++ b/tools/blktap2/drivers/block-qcow.c
@@ -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);
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
reply other threads:[~2014-06-20 14:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140620140854.19823.79938.stgit@Solace \
--to=dario.faggioli@citrix.com \
--cc=Dave.Scott@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=keir@xen.org \
--cc=thanos.makatos@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.