# HG changeset patch # User Matti Hamalainen # Date 1559507855 -10800 # Node ID 810fc98d9003acc3a20fd4020ebdfb21f3bcaf58 # Parent 487157934904cdee46f1684b2a33c05be7d46d5b Cleanups. diff -r 487157934904 -r 810fc98d9003 tools/lib64fmts.c --- 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);