From d3836d69630d1365453a80bd6f7792df8544fe25 Mon Sep 17 00:00:00 2001 From: des Date: Mon, 28 Oct 2002 10:19:03 +0000 Subject: Fix an off-by-one error (> where >= should have been used) which caused _fetch_writev() to incorrectly report EPIPE in certain cases. Also fix a number of const warnings by using __DECONST(), plus a signed / unsigned comparison by casting the rhs to ssize_t. Submitted by: fenner, Craig Rodrigues --- lib/libfetch/common.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/libfetch/common.c') diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c index 1ae9193..9252a36 100644 --- a/lib/libfetch/common.c +++ b/lib/libfetch/common.c @@ -458,7 +458,7 @@ _fetch_write(conn_t *conn, const char *buf, size_t len) { struct iovec iov; - iov.iov_base = (char *)buf; + iov.iov_base = __DECONST(char *, buf); iov.iov_len = len; return _fetch_writev(conn, &iov, 1); } @@ -525,15 +525,14 @@ _fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt) return (-1); } total += wlen; - while (iovcnt > 0 && wlen > iov->iov_len) { + while (iovcnt > 0 && wlen >= (ssize_t)iov->iov_len) { wlen -= iov->iov_len; iov++; iovcnt--; } if (iovcnt > 0) { iov->iov_len -= wlen; - iov->iov_base += wlen; - wlen = 0; + iov->iov_base = __DECONST(char *, iov->iov_base) + wlen; } } return (total); @@ -549,9 +548,9 @@ _fetch_putln(conn_t *conn, const char *str, size_t len) struct iovec iov[2]; DEBUG(fprintf(stderr, ">>> %s\n", str)); - iov[0].iov_base = (char *)str; + iov[0].iov_base = __DECONST(char *, str); iov[0].iov_len = len; - iov[1].iov_base = (char *)ENDL; + iov[1].iov_base = __DECONST(char *, ENDL); iov[1].iov_len = sizeof ENDL; if (_fetch_writev(conn, iov, 2) == -1) return (-1); -- cgit v1.1