From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzqrV-0005VB-H7 for qemu-devel@nongnu.org; Thu, 18 Jul 2013 12:15:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzqrS-0006wR-HF for qemu-devel@nongnu.org; Thu, 18 Jul 2013 12:15:25 -0400 Received: from mail-qa0-x235.google.com ([2607:f8b0:400d:c00::235]:37532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzqrS-0006wM-Dl for qemu-devel@nongnu.org; Thu, 18 Jul 2013 12:15:22 -0400 Received: by mail-qa0-f53.google.com with SMTP id g10so1802963qah.5 for ; Thu, 18 Jul 2013 09:15:22 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Thu, 18 Jul 2013 09:14:48 -0700 Message-Id: <1374164088-13146-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH] util/iov: Fix -O1 uninitialized variable warning List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com 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 --- 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