Mercurial > hg > dmlib
changeset 1853:2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Jun 2018 23:44:22 +0300 |
parents | 219417325036 |
children | 31c9884321b1 |
files | tools/lib64gfx.c |
diffstat | 1 files changed, 14 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/lib64gfx.c Fri Jun 22 23:40:20 2018 +0300 +++ b/tools/lib64gfx.c Fri Jun 22 23:44:22 2018 +0300 @@ -872,7 +872,7 @@ const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i); const Uint8 *src; DMC64MemBlock *blk = NULL; - const char *blkname = NULL; + const char *subjname = dmC64GetOpSubjectName(op->subject); size_t size; Uint8 value; @@ -888,18 +888,19 @@ if (!dmC64GetOpSize(op, fmt, &size)) { return dmError(DMERR_INVALID_DATA, - "Decode op SIZE out of bounds, op #%d type=%d, subj=%d, offs=%d ($%04x), " + "Decode op SIZE out of bounds, op #%d type=%d, subj=%s, offs=%d ($%04x), " "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n", - i, op->type, op->subject, op->offs, op->offs, op->bank, size, size, op->size, op->size); + i, op->type, subjname, op->offs, op->offs, op->bank, + size, size, op->size, op->size); } // Is the operation inside the bounds? if (op->offs + size > buf->len + 1) { return dmError(DMERR_INVALID_DATA, - "Decode DATA out of bounds, op #%d type=%d, subj=%d, offs=%d ($%04x), " + "Decode DATA out of bounds, op #%d type=%d, subj=%s, offs=%d ($%04x), " "bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - i, op->type, op->subject, op->offs, op->offs, op->bank, + i, op->type, subjname, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); } @@ -922,14 +923,13 @@ case DS_EXTRA_DATA: // XXX BZZZT .. a nasty cast here --v dmC64GetOpMemBlock(img, op->subject, op->bank, (const DMC64MemBlock **) &blk); - blkname = dmC64GetOpSubjectName(op->subject); if ((dmC64MemBlockReAlloc(blk, op->offs2 + size)) != DMERR_OK) { return dmError(DMERR_MALLOC, "Could not allocate '%s' block! " "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - blkname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); + subjname, i, op->offs, op->offs, op->bank, op->offs2 + size, op->offs2 + size, buf->len, buf->len); } switch (op->type) { @@ -1079,7 +1079,7 @@ const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i); size_t size, chksize; const DMC64MemBlock *blk = NULL; - const char *blkname = NULL; + const char *subjname = dmC64GetOpSubjectName(op->subject); Uint8 value; // Check for last operator @@ -1094,9 +1094,9 @@ if (!dmC64GetOpSize(op, fmt, &size)) { res = dmError(DMERR_INVALID_DATA, - "Encode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), " + "Encode op SIZE out of bounds, op #%d type=%d, subj=%s, offs=%d ($%04x), " "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n", - i, op->type, op->offs, op->offs, op->bank, size, size, buf->size, buf->size); + subjname, i, op->type, subjname, op->offs, op->offs, op->bank, size, size, buf->size, buf->size); goto err; } @@ -1125,8 +1125,6 @@ case DS_CHAR_DATA: case DS_EXTRA_DATA: dmC64GetOpMemBlock(img, op->subject, op->bank, &blk); - blkname = dmC64GetOpSubjectName(op->subject); - switch (op->type) { case DO_COPY: @@ -1135,7 +1133,7 @@ res = dmError(DMERR_NULLPTR, "'%s' block is NULL in " "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - blkname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); + subjname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); goto err; } if (op->offs2 + size > blk->size) @@ -1143,7 +1141,7 @@ res = dmError(DMERR_INTERNAL, "'%s' size mismatch %d <> %d in " "op #%d, offs=%d ($%04x), bank=%d, offs2=%d ($%02x), size=%d ($%04x)\n", - blkname, op->offs2 + size, blk->size, i, op->offs, op->offs, op->bank, op->offs2, op->offs2, size, size); + subjname, op->offs2 + size, blk->size, i, op->offs, op->offs, op->bank, op->offs2, op->offs2, size, size); goto err; } memcpy(dst, blk->data + op->offs2, size); @@ -1197,9 +1195,9 @@ default: return dmError(DMERR_INTERNAL, - "Unhandled subject %d in " + "Unhandled subject '%s' in " "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", - op->subject, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); + subjname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); } break;