From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: peter.maydell@linaro.org, aliguori@us.ibm.com,
qemu-devel@nongnu.org, mlureau@redhat.com, stefanha@redhat.com,
pbonzini@redhat.com, alevy@redhat.com,
Robert Relyea <rrelyea@redhat.com>
Subject: Re: [Qemu-devel] [PATCH V2] build: remove compile warning
Date: Sat, 08 Jun 2013 10:04:16 +0800 [thread overview]
Message-ID: <51B29120.30102@linux.vnet.ibm.com> (raw)
In-Reply-To: <87ehcedsi7.fsf@blackfin.pond.sub.org>
I insist to remove compile warning since I want gcc check my code with
strict rule.
> Wenchao Xia <xiawenc@linux.vnet.ibm.com> writes:
>
>> This patch simply remove "variable may be used uninitialized" warning.
>>
>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>> ---
>> 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
next prev parent reply other threads:[~2013-06-08 2:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-07 10:02 [Qemu-devel] [PATCH V2] build: remove compile warning Wenchao Xia
2013-06-07 11:35 ` Stefan Hajnoczi
2013-06-07 12:17 ` Markus Armbruster
2013-06-08 2:04 ` Wenchao Xia [this message]
2013-06-18 10:14 ` Paolo Bonzini
2013-06-18 10:13 ` Paolo Bonzini
2013-06-19 6:27 ` Wenchao Xia
2013-06-19 9:33 ` Paolo Bonzini
2013-06-22 10:03 ` Stefan Weil
2013-06-24 14:44 ` Paolo Bonzini
2013-06-24 17:58 ` Stefan Weil
2013-06-26 8:12 ` Paolo Bonzini
2013-06-25 1:50 ` Wenchao Xia
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=51B29120.30102@linux.vnet.ibm.com \
--to=xiawenc@linux.vnet.ibm.com \
--cc=alevy@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=mlureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rrelyea@redhat.com \
--cc=stefanha@redhat.com \
/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.