commit 744d93265df30ca836528ad12d5c1d0d980570a9 from: Stefan Sperling date: Fri Dec 01 21:38:52 2017 UTC fix size calculations commit - a3e2cbea8743ac575f4afe7fa29ff08a3ff46135 commit + 744d93265df30ca836528ad12d5c1d0d980570a9 blob - 779aab71c261e47a042a8cefc186efdbad3e3625 blob + 5274de47c0e7d96705975773efe4b2f31d60d543 --- lib/object.c +++ lib/object.c @@ -204,17 +204,16 @@ read_object_header(struct got_object **obj, struct got FILE *f; struct got_zstream_buf zb; char *buf; - size_t totalsz; + size_t len; const size_t zbsize = 64; - size_t outlen; + size_t outlen, totlen; int i, ret; f = fopen(path, "rb"); if (f == NULL) return got_error(GOT_ERR_BAD_PATH); - totalsz = zbsize; - buf = calloc(totalsz, sizeof(char)); + buf = calloc(zbsize, sizeof(char)); if (buf == NULL) return got_error(GOT_ERR_NO_MEM); @@ -225,19 +224,19 @@ read_object_header(struct got_object **obj, struct got } i = 0; + totlen = 0; do { err = inflate_read(&zb, f, &outlen); if (err) goto done; - if (strchr(zb.outbuf, '\0') == NULL) { + if (strchr(zb.outbuf, '\0') == NULL) buf = recallocarray(buf, 1 + i, 2 + i, zbsize); - totalsz += zbsize; - } - memcpy(buf, zb.outbuf, zbsize); + memcpy(buf, zb.outbuf, outlen); + totlen += outlen; i++; } while (strchr(zb.outbuf, '\0') == NULL); - err = parse_object_header(obj, buf, totalsz); + err = parse_object_header(obj, buf, totlen); done: inflate_end(&zb); fclose(f);