changeset 2149:810fc98d9003

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 02 Jun 2019 23:37:35 +0300
parents 487157934904
children b4fbb90937f7
files tools/lib64fmts.c
diffstat 1 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Sun Jun 02 23:12:53 2019 +0300
+++ b/tools/lib64fmts.c	Sun Jun 02 23:37:35 2019 +0300
@@ -983,22 +983,25 @@
     int res;
     DMGrowBuf src, tmp;
     DMCompParams cfg;
-    Uint8 data, count;
+    Uint8 data, count, *dstBuf;
     const size_t dstSize = 0x7ff2 - 0x4000;
     size_t dstOffs;
-    Uint8 *dstBuf;
     BOOL getByte = TRUE;
 
-    if ((dstBuf = dmMalloc0(dstSize)) == NULL)
-    {
-        return dmError(DMERR_MALLOC,
-            "Could not allocate memory for RLE decoding buffer.\n");
-    }
-
+    // Setup the RLE config, only for input
     cfg.func         = fmt->name;
     cfg.type         = DM_COMP_RLE_MARKER;
     cfg.flags        = DM_RLE_BACKWARDS_INPUT;
 
+    // Allocate output buffer
+    if ((dstBuf = dmMalloc0(dstSize)) == NULL)
+    {
+        return dmError(DMERR_MALLOC,
+            "%s: Could not allocate memory for RLE decoding buffer.\n",
+            cfg.func);
+    }
+
+    // Setup input buffer
     dmGrowBufConstCopy(&src, psrc);
     dmSetupRLEBuffers(NULL, &src, &cfg);
     dstOffs = dstSize;
@@ -1038,17 +1041,19 @@
             for (int n = 0; n < ncount; n++)
             {
                 if (!dmGrowBufGetU8(&src, &data))
-                    break;
+                    goto finish;
 
                 if (dstOffs > 0)
                     dstBuf[--dstOffs] = data;
                 else
-                    break;
+                    goto finish;
             }
             getByte = FALSE;
         }
     }
 
+finish:
+
     dmGrowBufConstCreateFrom(&tmp, dstBuf, 0x3fff);
     res = dmC64DecodeGenericBMP(img, &tmp, fmt);