qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning


From: Richard Henderson
Subject: [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning
Date: Thu, 18 Jul 2013 09:14:48 -0700

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]