util/iov: Fix -O1 uninitialized variable warning
PATCH 1/1 util/iov: Fix -O1 uninitialized variable warning
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.
--- util/iov.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
util/iov.c +8 -7
@@ -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;
Signature · 1 line
1.8.1.4
Quoted 6 lines · Richard Henderson
At -O2, code in the form
if (p) A; B; if (p) C;
may be rearranged via "jump threading" into
Quoted 7 lines
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 <[email protected]>
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
Quoted 13 lines · Peter Maydell
Quoted 12 lines · Richard Henderson
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.
Quoted 6 lines
Quoted 1 line
Signed-off-by Richard Henderson <[email protected]>This is the same issue fixed by this (reviewed but never applied) patch from June, isn't it?
Yes, it is.
r~