Skip to content

Commit b02479a

Browse files
committed
read(2) with nbytes=0 can fail.
1 parent 6e9ec67 commit b02479a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/safe_rw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ safe_read(const int fd, void * const buf_, size_t count)
4343
unsigned char *buf = (unsigned char *) buf_;
4444
ssize_t readnb;
4545

46-
do {
46+
while (count > (ssize_t) 0) {
4747
while ((readnb = read(fd, buf, count)) < (ssize_t) 0 &&
4848
errno == EINTR);
4949
if (readnb < (ssize_t) 0) {
@@ -54,7 +54,7 @@ safe_read(const int fd, void * const buf_, size_t count)
5454
}
5555
count -= readnb;
5656
buf += readnb;
57-
} while (count > (ssize_t) 0);
57+
}
5858

5959
return (ssize_t) (buf - (unsigned char *) buf_);
6060
}

0 commit comments

Comments
 (0)