# HG changeset patch # User Matti Hamalainen # Date 1525982889 -10800 # Node ID b9d3577d82902bab7255bf72f42361256dcf05bf # Parent a988baa5b21ffe063902ae8a048c3846b6020c95 Improve error handling and checking. diff -r a988baa5b21f -r b9d3577d8290 tools/lib64gfx.c --- a/tools/lib64gfx.c Thu May 10 23:07:50 2018 +0300 +++ b/tools/lib64gfx.c Thu May 10 23:08:09 2018 +0300 @@ -1365,10 +1365,19 @@ if (img == NULL || fmt == NULL) return DMERR_NULLPTR; + // Sanity check img vs format + if (img->type != fmt->type || + img->width != fmt->width || img->height != fmt->height) + { + res = dmError(DMERR_NOT_SUPPORTED, + "Can't directly encode a differing C64 bitmap image format.\n"); + goto err; + } + // Allocate the output buffer if ((res = dmGrowBufAlloc(buf, fmt->size, BUF_SIZE_GROW)) != DMERR_OK) { - return dmError(res, + dmError(res, "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", fmt->size); goto err; @@ -1725,10 +1734,13 @@ { int res; - if (img == NULL) + if (img == NULL || fmt == NULL) return DMERR_NULLPTR; // Attempt to encode the image to a buffer + if ((res = dmGrowBufInit(buf)) != DMERR_OK) + return res; + if (fmt->encode != NULL) res = fmt->encode(buf, img, fmt); else