qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH V2] build: remove compile warning


From: Wenchao Xia
Subject: Re: [Qemu-devel] [PATCH V2] build: remove compile warning
Date: Sat, 08 Jun 2013 10:04:16 +0800
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6

  I insist to remove compile warning since I want gcc check my code with
strict rule.

Wenchao Xia <address@hidden> writes:

This patch simply remove "variable may be used uninitialized" warning.

Signed-off-by: Wenchao Xia <address@hidden>
---
V2: Address Stefan and Peter's comments, use 0 in send_msg() instead of
initialize mhHeader.

  libcacard/vscclient.c |    3 +--
  util/iov.c            |    2 +-
  2 files changed, 2 insertions(+), 3 deletions(-)



diff --git a/util/iov.c b/util/iov.c
index cc6e837..b91cfb9 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 orig_len = 0, tail;
      unsigned niov;

      while (bytes > 0) {

Here are the uses of orig_len:

         if (tail) {
             /* second, fixup the last element, and remember the original
              * length */
             assert(niov < iov_cnt);
             assert(iov[niov].iov_len > tail);
             orig_len = iov[niov].iov_len;
             iov[niov++].iov_len = tail;
         }

         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;
         }


gcc is too stupid to understand the control flow.  The initialization
shuts it up.

Personally, I dislike "shut up" initializations, because when you
mistakenly adds a new uninitialized use, you get the arbitrary "shut up"
value without warning.

Possible alternative:

         if (tail) {
             /* second, fixup the last element, and remember the original
              * length */
             assert(niov < iov_cnt);
             assert(iov[niov].iov_len > tail);
             orig_len = iov[niov].iov_len;
             iov[niov++].iov_len = tail;
             ret = do_send_recv(sockfd, iov, niov, do_send);
             /* Undo the changes above before checking for errors */
             iov[niov-1].iov_len = orig_len;
         } else {
             ret = do_send_recv(sockfd, iov, niov, do_send);
         }

  OK to work, but duplicated a line. I think it is not bad to give
default value as zero, even there will be new use later.

--
Best Regards

Wenchao Xia




reply via email to

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