aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-29 15:41:41 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-29 15:41:41 +0200
commit7636f0977cff47e152594902b69d99d9f0fc0232 (patch)
treed2170bde143bb2dbedede4cfca4373d91f3a1642
parentbe2ca1ba42029b80cffff78afee77abf9831131a (diff)
downloadmblaze-7636f0977cff47e152594902b69d99d9f0fc0232.tar.gz
blaze822: blaze822_file: allocate enough space for read
-rw-r--r--blaze822.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/blaze822.c b/blaze822.c
index f8b5812..69f317d 100644
--- a/blaze822.c
+++ b/blaze822.c
@@ -454,19 +454,20 @@ blaze822_file(char *file)
goto error;
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);
if (!buf)
goto error;
do {
- if (bufalloc <= rd) {
+ if (bufalloc < rd + bufblk) {
bufalloc *= 2;
buf = realloc(buf, bufalloc);
if (!buf)
goto error;
}
- if ((n = read(fd, buf + rd, 16384)) < 0) {
+ if ((n = read(fd, buf + rd, bufblk)) < 0) {
if (errno == EINTR) {
continue;
} else {