From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning
Date: Thu, 18 Jul 2013 09:14:48 -0700 [thread overview]
Message-ID: <1374164088-13146-1-git-send-email-rth@twiddle.net> (raw)
At -O2, code in the form
if (p) A; B; if (p) C;
may be rearranged via "jump threading" into
if (p) { A; B; C; } else { B; }
But at -O1 this doesn't happen and we -Werror out here on
the "may be used uninitialized" orig_len. Perform this transform
by hand so that -O1 remains a viable debugging alternative.
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
util/iov.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/util/iov.c b/util/iov.c
index cc6e837..a92eb3a 100644
--- a/util/iov.c
+++ b/util/iov.c
@@ -146,7 +146,7 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
{
ssize_t total = 0;
ssize_t ret;
- size_t orig_len, tail;
+ size_t tail;
unsigned niov;
while (bytes > 0) {
@@ -174,21 +174,22 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,
for (niov = 0; niov < iov_cnt && iov[niov].iov_len <= tail; ++niov) {
tail -= iov[niov].iov_len;
}
+
if (tail) {
/* second, fixup the last element, and remember the original
* length */
+ size_t orig_len = iov[niov].iov_len;
assert(niov < iov_cnt);
- assert(iov[niov].iov_len > tail);
- orig_len = iov[niov].iov_len;
+ assert(orig_len > tail);
iov[niov++].iov_len = tail;
- }
- ret = do_send_recv(sockfd, iov, niov, do_send);
+ ret = do_send_recv(sockfd, iov, niov, do_send);
- /* Undo the changes above before checking for errors */
- if (tail) {
iov[niov-1].iov_len = orig_len;
+ } else {
+ ret = do_send_recv(sockfd, iov, niov, do_send);
}
+
if (offset) {
iov[0].iov_base -= offset;
iov[0].iov_len += offset;
--
1.8.1.4
next reply other threads:[~2013-07-18 16:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-18 16:14 Richard Henderson [this message]
2013-07-18 16:36 ` [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning Peter Maydell
2013-07-18 17:09 ` Richard Henderson
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=1374164088-13146-1-git-send-email-rth@twiddle.net \
--to=rth@twiddle.net \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).