summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/common.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-10-28 10:19:03 +0000
committerdes <des@FreeBSD.org>2002-10-28 10:19:03 +0000
commitd3836d69630d1365453a80bd6f7792df8544fe25 (patch)
treec3455ee09d1fe5403e6bd7cefb2e1a0fb551b028 /lib/libfetch/common.c
parent2e561443676abf3f67d1ea9f782e100a6e20bf70 (diff)
downloadFreeBSD-src-d3836d69630d1365453a80bd6f7792df8544fe25.zip
FreeBSD-src-d3836d69630d1365453a80bd6f7792df8544fe25.tar.gz
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 <rodrigc@attbi.com>
Diffstat (limited to 'lib/libfetch/common.c')
-rw-r--r--lib/libfetch/common.c11
1 files changed, 5 insertions, 6 deletions
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);
OpenPOWER on IntegriCloud