blaze822: blaze822_file: allocate enough space for read

pull/2/head
Christian Neukirchen 8 years ago
parent be2ca1ba42
commit 7636f0977c

@ -454,19 +454,20 @@ blaze822_file(char *file)
goto error; goto error;
if (S_ISFIFO(st.st_mode)) { // unbounded read, grow buffer if (S_ISFIFO(st.st_mode)) { // unbounded read, grow buffer
ssize_t bufalloc = 16384; const ssize_t bufblk = 16384;
ssize_t bufalloc = bufblk;
buf = malloc(bufalloc); buf = malloc(bufalloc);
if (!buf) if (!buf)
goto error; goto error;
do { do {
if (bufalloc <= rd) { if (bufalloc < rd + bufblk) {
bufalloc *= 2; bufalloc *= 2;
buf = realloc(buf, bufalloc); buf = realloc(buf, bufalloc);
if (!buf) if (!buf)
goto error; goto error;
} }
if ((n = read(fd, buf + rd, 16384)) < 0) { if ((n = read(fd, buf + rd, bufblk)) < 0) {
if (errno == EINTR) { if (errno == EINTR) {
continue; continue;
} else { } else {

Loading…
Cancel
Save