comparison tools/lib64gfx.c @ 1460:361cad3b8445

Improve error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 10 May 2018 21:19:55 +0300
parents dcff9ac95d3f
children 96c254579b82
comparison
equal deleted inserted replaced
1459:1155f4bc4afc 1460:361cad3b8445
1112 1112
1113 1113
1114 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, 1114 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf,
1115 const size_t len, const DMC64ImageFormat *fmt) 1115 const size_t len, const DMC64ImageFormat *fmt)
1116 { 1116 {
1117 int res = DMERR_OK;
1118
1117 if (buf == NULL || img == NULL || fmt == NULL) 1119 if (buf == NULL || img == NULL || fmt == NULL)
1118 return DMERR_NULLPTR; 1120 return DMERR_NULLPTR;
1119 1121
1120 // Clear the image structure, set basics 1122 // Clear the image structure, set basics
1121 img->type = fmt->type; 1123 img->type = fmt->type;
1129 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) 1131 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
1130 { 1132 {
1131 const DMC64EncDecOp *op = &fmt->encdecOps[i]; 1133 const DMC64EncDecOp *op = &fmt->encdecOps[i];
1132 const Uint8 *src; 1134 const Uint8 *src;
1133 size_t size; 1135 size_t size;
1134 int res;
1135 1136
1136 // Check for last operator 1137 // Check for last operator
1137 if (op->type == DT_LAST) 1138 if (op->type == DT_LAST)
1138 break; 1139 break;
1139 1140
1421 // Sanity check arguments 1422 // Sanity check arguments
1422 if (dst == NULL || src == NULL) 1423 if (dst == NULL || src == NULL)
1423 return DMERR_NULLPTR; 1424 return DMERR_NULLPTR;
1424 1425
1425 if (dst->width < src->width || dst->height < src->height) 1426 if (dst->width < src->width || dst->height < src->height)
1426 return DMERR_INVALID_DATA; 1427 {
1428 return dmError(DMERR_INVALID_DATA,
1429 "Invalid src vs. dst width/height %d x %d <-> %d x %d\n",
1430 src->width, src->height, dst->width, dst->height);
1431 }
1427 1432
1428 dmMemset(dst->data, 0, dst->size); 1433 dmMemset(dst->data, 0, dst->size);
1429 1434
1430 // Check pixel getter function 1435 // Check pixel getter function
1431 if (fmt->getPixel != NULL) 1436 if (fmt->getPixel != NULL)
1583 *fmt = forced; 1588 *fmt = forced;
1584 else 1589 else
1585 { 1590 {
1586 // Nope, perform a generic probe 1591 // Nope, perform a generic probe
1587 if (probeOffs >= len) 1592 if (probeOffs >= len)
1588 return DMERR_INVALID_DATA; 1593 return DMERR_OUT_OF_DATA;
1589 1594
1590 if (dmC64ProbeBMP(buf + probeOffs, len - probeOffs, fmt) == DM_PROBE_SCORE_FALSE) 1595 if (dmC64ProbeBMP(buf + probeOffs, len - probeOffs, fmt) == DM_PROBE_SCORE_FALSE)
1591 return DMERR_INVALID_DATA; 1596 return DMERR_NOT_SUPPORTED;
1592 } 1597 }
1593 1598
1594 if (loadOffs >= len) 1599 if (loadOffs >= len)
1595 return DMERR_INVALID_ARGS; 1600 return DMERR_INVALID_ARGS;
1596 1601