replace reallocarray with recallocarray throughout inflate.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/lib/inflate.c b/lib/inflate.c
index cacf5c9..8d7a9af 100644
--- a/lib/inflate.c
+++ b/lib/inflate.c
@@ -208,6 +208,7 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
size_t avail;
struct got_zstream_buf zb;
void *newbuf;
+ int nbuf = 1;
*outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE);
if (*outbuf == NULL)
@@ -224,8 +225,9 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
goto done;
*outlen += avail;
if (zb.flags & GOT_ZSTREAM_F_HAVE_MORE) {
- newbuf = reallocarray(*outbuf, 1,
- *outlen + GOT_ZSTREAM_BUFSIZE);
+ nbuf++;
+ newbuf = recallocarray(*outbuf, nbuf - 1, nbuf,
+ GOT_ZSTREAM_BUFSIZE);
if (newbuf == NULL) {
err = got_error_from_errno();
free(*outbuf);
@@ -235,7 +237,7 @@ got_inflate_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
}
*outbuf = newbuf;
zb.outbuf = newbuf + *outlen;
- zb.outlen = GOT_ZSTREAM_BUFSIZE;
+ zb.outlen = (nbuf * GOT_ZSTREAM_BUFSIZE) - *outlen;
}
} while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
@@ -251,6 +253,7 @@ got_inflate_to_mem_fd(uint8_t **outbuf, size_t *outlen, int infd)
size_t avail;
struct got_zstream_buf zb;
void *newbuf;
+ int nbuf = 1;
*outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE);
if (*outbuf == NULL)
@@ -267,8 +270,9 @@ got_inflate_to_mem_fd(uint8_t **outbuf, size_t *outlen, int infd)
goto done;
*outlen += avail;
if (zb.flags & GOT_ZSTREAM_F_HAVE_MORE) {
- newbuf = reallocarray(*outbuf, 1,
- *outlen + GOT_ZSTREAM_BUFSIZE);
+ nbuf++;
+ newbuf = recallocarray(*outbuf, nbuf - 1, nbuf,
+ GOT_ZSTREAM_BUFSIZE);
if (newbuf == NULL) {
err = got_error_from_errno();
free(*outbuf);
@@ -278,7 +282,7 @@ got_inflate_to_mem_fd(uint8_t **outbuf, size_t *outlen, int infd)
}
*outbuf = newbuf;
zb.outbuf = newbuf + *outlen;
- zb.outlen = GOT_ZSTREAM_BUFSIZE;
+ zb.outlen = (nbuf * GOT_ZSTREAM_BUFSIZE) - *outlen;
}
} while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);