qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning
@ 2013-07-18 16:14 Richard Henderson
  2013-07-18 16:36 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2013-07-18 16:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning
  2013-07-18 16:14 [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning Richard Henderson
@ 2013-07-18 16:36 ` Peter Maydell
  2013-07-18 17:09   ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2013-07-18 16:36 UTC (permalink / raw)
  To: Richard Henderson; +Cc: aliguori, qemu-devel

On 18 July 2013 17:14, Richard Henderson <rth@twiddle.net> wrote:
> 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>

This is the same issue fixed by this (reviewed but
never applied) patch from June, isn't it?

http://patchwork.ozlabs.org/patch/251410/

thanks
-- PMM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning
  2013-07-18 16:36 ` Peter Maydell
@ 2013-07-18 17:09   ` Richard Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2013-07-18 17:09 UTC (permalink / raw)
  To: Peter Maydell; +Cc: aliguori, qemu-devel

On 07/18/2013 09:36 AM, Peter Maydell wrote:
> On 18 July 2013 17:14, Richard Henderson <rth@twiddle.net> wrote:
>> 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>
> 
> This is the same issue fixed by this (reviewed but
> never applied) patch from June, isn't it?
> 
> http://patchwork.ozlabs.org/patch/251410/

Yes, it is.


r~

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-18 17:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-18 16:14 [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning Richard Henderson
2013-07-18 16:36 ` Peter Maydell
2013-07-18 17:09   ` Richard Henderson

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).