Mercurial > hg > dmlib
changeset 1649:dbdff3d50a4e
Clean up fmtDecodeTruePaintPacked() a bit, and fix GCC warnings about
(intentional) switch/case fallthroughs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 30 May 2018 01:29:09 +0300 |
parents | 52cd979d63fd |
children | 9233da9de92c |
files | tools/lib64fmts.c |
diffstat | 1 files changed, 22 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/lib64fmts.c Wed May 30 01:18:26 2018 +0300 +++ b/tools/lib64fmts.c Wed May 30 01:29:09 2018 +0300 @@ -333,6 +333,19 @@ // Based on disassembly of the depacker routine. Encoding seems to be // some kind of "improved RLE" variant. // +static BOOL fmtTruePaintGetByte(const Uint8 *src, size_t *srcOffs, Uint8 *data, int *res, const int mode) +{ + if (!dmReverseGetByte(src, srcOffs, data)) + { + *res = dmError(DMERR_INVALID_DATA, + "TruePaintRLE: Out of input data (N=%d)\n", mode); + return FALSE; + } + else + return TRUE; +} + + static int fmtDecodeTruePaintPacked(DMC64Image *img, const Uint8 *src, const size_t srcLen, const DMC64ImageFormat *fmt) { int res = DMERR_OK; @@ -366,12 +379,8 @@ int count = 1, scount; BOOL found = FALSE; - if (!dmReverseGetByte(src, &srcOffs, &data)) - { - res = dmError(DMERR_INVALID_DATA, - "TruePaintRLE: Out of source data.\n"); + if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, -1)) goto out; - } for (int n = 0; n < 8; n++) if (codeBook1[n] == data && !found) @@ -380,43 +389,30 @@ switch (n) { case 4: // Y = 4, JTO = $0B - if (!dmReverseGetByte(src, &srcOffs, &data)) - { - res = dmError(DMERR_INVALID_DATA, - "TruePaintRLE: Y=4, JTO=$0B\n"); + if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, n)) goto out; - } count = data; if (data == 0) - { - fprintf(stderr, "TruePaintRLE: BAILOUT\n"); goto finish; - } - // NOTE: Intentional fall through here! + + // fallthrough case 1: // Y = 1, JTO = $17 count += 2; - // NOTE: Intentional fallthrough here! + // fallthrough case 0: // Y = 0, JTO = $19 - if (!dmReverseGetByte(src, &srcOffs, &data)) - { - res = dmError(DMERR_INVALID_DATA, - "TruePaintRLE: Y=0, JTO=$19\n"); + if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, n)) goto out; - } break; case 2: // Y = 2, JTO = $07 - if (!dmReverseGetByte(src, &srcOffs, &data)) - { - res = dmError(DMERR_INVALID_DATA, - "foo: Y=2, JTO=$07\n"); + if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, n)) goto out; - } + count = data; - // NOTE: Intentional fallthrough here! + // fallthrough case 3: // Y = 3, JTO = $0B count += 2;