Mercurial > hg > dmlib
diff tools/lib64fmts.c @ 1748:9c4b3fecc510
Use the new DMGrowBuf functions in XX2 format buffer enlarging.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 11 Jun 2018 14:21:09 +0300 |
parents | 5e928618fdc8 |
children | feaf5cf07603 |
line wrap: on
line diff
--- a/tools/lib64fmts.c Mon Jun 11 13:57:07 2018 +0300 +++ b/tools/lib64fmts.c Mon Jun 11 14:21:09 2018 +0300 @@ -531,15 +531,13 @@ // If there is only data for less than XX2_MIN_SIZE bytes, // allocate a buffer of that size and copy data there. // Otherwise allocate len bytes. - size_t nlen = buf->len < XX2_MIN_SIZE ? XX2_MIN_SIZE : buf->len; - Uint8 *mem = dmMalloc0(nlen); - if (mem == NULL) + if (dmGrowBufCopy(&tmp, buf, buf->len < XX2_MIN_SIZE ? XX2_MIN_SIZE - buf->len : 0) == NULL) return DMERR_MALLOC; - memcpy(mem, buf->data, buf->len); - res = dmC64DecodeGenericBMP(img, dmGrowBufCreateFrom(&tmp, mem, nlen), fmt); + tmp.len = tmp.size; + res = dmC64DecodeGenericBMP(img, &tmp, fmt); + dmGrowBufFree(&tmp); - dmFree(mem); return res; }