changeset 966:c91befdb668b

Fixes and cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 05:23:25 +0200
parents df8d2ad98f7d
children b387481e511e
files src/stb_image.c
diffstat 1 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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