From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul8Wv-0007yc-1t for qemu-devel@nongnu.org; Fri, 07 Jun 2013 22:05:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ul8Wt-00023W-6V for qemu-devel@nongnu.org; Fri, 07 Jun 2013 22:05:21 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:49409) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul8Ws-00023Q-KJ for qemu-devel@nongnu.org; Fri, 07 Jun 2013 22:05:19 -0400 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 8 Jun 2013 23:02:03 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 3CE2A2CE8044 for ; Sat, 8 Jun 2013 12:05:12 +1000 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r581oht030671094 for ; Sat, 8 Jun 2013 11:50:43 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5825A77002212 for ; Sat, 8 Jun 2013 12:05:11 +1000 Message-ID: <51B29120.30102@linux.vnet.ibm.com> Date: Sat, 08 Jun 2013 10:04:16 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1370599329-16682-1-git-send-email-xiawenc@linux.vnet.ibm.com> <87ehcedsi7.fsf@blackfin.pond.sub.org> In-Reply-To: <87ehcedsi7.fsf@blackfin.pond.sub.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V2] build: remove compile warning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster 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 I insist to remove compile warning since I want gcc check my code with strict rule. > Wenchao Xia writes: > >> This patch simply remove "variable may be used uninitialized" warning. >> >> Signed-off-by: Wenchao Xia >> --- >> 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