comparison tools/lib64gfx.c @ 1727:8eb5ff34864a

Improve error messages in the RLE decoder.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 07 Jun 2018 15:21:54 +0300
parents f9128665a47e
children 80adcda72210
comparison
equal deleted inserted replaced
1726:f9128665a47e 1727:8eb5ff34864a
383 if (data == cfg->rleMarkerB && (cfg->flags & DM_RLE_BYTE_RUNS)) 383 if (data == cfg->rleMarkerB && (cfg->flags & DM_RLE_BYTE_RUNS))
384 { 384 {
385 if (!dmGrowBufGetU8(&src, &tmp1) || 385 if (!dmGrowBufGetU8(&src, &tmp1) ||
386 !dmGrowBufGetU8(&src, &tmp2)) 386 !dmGrowBufGetU8(&src, &tmp2))
387 { 387 {
388 res = DMERR_INVALID_DATA; 388 res = dmError(DMERR_INVALID_DATA,
389 "%s: RLE: Invalid data/out of data for byte length run sequence.\n",
390 cfg->func);
389 goto out; 391 goto out;
390 } 392 }
391 switch (cfg->flags & DM_RLE_ORDER_MASK) 393 switch (cfg->flags & DM_RLE_ORDER_MASK)
392 { 394 {
393 case DM_RLE_ORDER_1: 395 case DM_RLE_ORDER_1:
406 { 408 {
407 if (!dmGrowBufGetU8(&src, &tmp1) || 409 if (!dmGrowBufGetU8(&src, &tmp1) ||
408 !dmGrowBufGetU8(&src, &tmp2) || 410 !dmGrowBufGetU8(&src, &tmp2) ||
409 !dmGrowBufGetU8(&src, &tmp3)) 411 !dmGrowBufGetU8(&src, &tmp3))
410 { 412 {
411 res = DMERR_INVALID_DATA; 413 res = dmError(DMERR_INVALID_DATA,
414 "%s: RLE: Invalid data/out of data for word length run sequence.\n",
415 cfg->func);
412 goto out; 416 goto out;
413 } 417 }
414 switch (cfg->flags & DM_RLE_ORDER_MASK) 418 switch (cfg->flags & DM_RLE_ORDER_MASK)
415 { 419 {
416 case DM_RLE_ORDER_1: 420 case DM_RLE_ORDER_1:
432 // and the lower bits contain the count: [Mask + count] [data] 436 // and the lower bits contain the count: [Mask + count] [data]
433 if ((data & cfg->rleMarkerMask) == cfg->rleMarkerBits) 437 if ((data & cfg->rleMarkerMask) == cfg->rleMarkerBits)
434 { 438 {
435 if (!dmGrowBufGetU8(&src, &tmp1)) 439 if (!dmGrowBufGetU8(&src, &tmp1))
436 { 440 {
437 res = DMERR_INVALID_DATA; 441 res = dmError(DMERR_INVALID_DATA,
442 "%s: RLE: Invalid data/out of data for byte length mask/run sequence.\n",
443 cfg->func);
438 goto out; 444 goto out;
439 } 445 }
440 446
441 count = data & cfg->rleCountMask; 447 count = data & cfg->rleCountMask;
442 data = tmp1; 448 data = tmp1;
834 break; 840 break;
835 841
836 case DO_SET_OP: 842 case DO_SET_OP:
837 memset(blk->data, op->offs, size); 843 memset(blk->data, op->offs, size);
838 break; 844 break;
845
839 default: 846 default:
840 return dmError(DMERR_INTERNAL, 847 return dmError(DMERR_INTERNAL,
841 "Unhandled op type %d in " 848 "Unhandled op type %d in "
842 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", 849 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
843 op->type, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); 850 op->type, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);