# HG changeset patch # User Matti Hamalainen # Date 1425007405 -7200 # Node ID c91befdb668be90700c349e9028efb3e791cc8c5 # Parent df8d2ad98f7db36c9d78666b495228eab9607ebf Fixes and cleanups. diff -r df8d2ad98f7d -r c91befdb668b src/stb_image.c --- a/src/stb_image.c Fri Feb 27 05:22:20 2015 +0200 +++ b/src/stb_image.c Fri Feb 27 05:23:25 2015 +0200 @@ -3706,30 +3706,32 @@ DMZLibContext ctx; int ret; - if ((*outBuf = dmMalloc(initialSize)) == NULL) - return 0; + if ((ctx.zout = ctx.zoutStart = dmMalloc(initialSize)) == NULL) + { + ret = dmError(DMERR_MALLOC, + "Failed to allocate initial decompression buffer.\n"); + goto err; + } ctx.zbuffer = (Uint8 *) inBuf; ctx.zbufferEnd = (Uint8 *) inBuf + inLen; - ctx.zout = *outBuf; - ctx.zoutStart = *outBuf; - ctx.zoutEnd = *outBuf + initialSize; + ctx.zoutEnd = ctx.zoutStart + initialSize; ctx.expandable = TRUE; if (parseHeader && (ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK) - { - return dmError(ret, - "Failed to parse zlib header data.\n"); - } + goto err; if ((ret = dmZLibDecode(&ctx)) != DMERR_OK) - { - dmFree(*outBuf); - return ret; - } + goto err; + *outBuf = ctx.zoutStart; *outLen = ctx.zout - ctx.zoutStart; return DMERR_OK; + +err: + dmFree(*outBuf); + *outBuf = NULL; + return ret; } @@ -3853,8 +3855,8 @@ raw_len, !is_iphone) != DMERR_OK) return 0; - if (z->expanded == NULL) return 0; // zlib should set error STBI_FREE(z->idata); z->idata = NULL; + if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) s->img_out_n = s->img_n+1; else