Cast the mallocs to their variable type.

Check that read and write actually return greater than zero.
This commit is contained in:
Con Kolivas 2011-02-11 11:46:58 +11:00
parent 3879807865
commit f2d33c00f8
2 changed files with 4 additions and 4 deletions

View file

@ -71,7 +71,7 @@ static i64 unzip_literal(void *ss, i64 len, int fd_out, uint32 *cksum)
if (unlikely(len < 0))
fatal("len %lld is negative in unzip_literal!\n",len);
buf = malloc(len);
buf = (uchar *)malloc(len);
if (unlikely(!buf))
fatal("Failed to malloc literal buffer of size %lld\n", len);
@ -110,7 +110,7 @@ static i64 unzip_match(void *ss, i64 len, int fd_out, int fd_hist, uint32 *cksum
uchar *buf;
n = MIN(len, offset);
buf = malloc(n);
buf = (uchar *)malloc(n);
if (unlikely(!buf))
fatal("Failed to malloc match buffer of size %lld\n", n);

View file

@ -606,7 +606,7 @@ ssize_t write_1g(int fd, void *buf, i64 len)
else
ret = len;
ret = write(fd, offset_buf, (size_t)ret);
if (unlikely(ret < 0))
if (unlikely(ret <= 0))
return ret;
len -= ret;
offset_buf += ret;
@ -629,7 +629,7 @@ ssize_t read_1g(int fd, void *buf, i64 len)
else
ret = len;
ret = read(fd, offset_buf, (size_t)ret);
if (unlikely(ret < 0))
if (unlikely(ret <= 0))
return ret;
len -= ret;
offset_buf += ret;