# HG changeset patch # User Matti Hamalainen # Date 1424724711 -7200 # Node ID be5d276f8a6ca65bec483790d7bbf10a4b5f322e # Parent 03bda6477ad4700630daf44ec412ab76089a2eee Some work on error handling. diff -r 03bda6477ad4 -r be5d276f8a6c tools/gfxconv.c --- a/tools/gfxconv.c Mon Feb 23 22:51:28 2015 +0200 +++ b/tools/gfxconv.c Mon Feb 23 22:51:51 2015 +0200 @@ -1247,6 +1247,7 @@ int dmWriteSpritesAndChars(const char *filename, DMImage *image, int outFormat, BOOL multicolor) { + int ret = DMERR_OK; int outBlockW, outBlockH, bx, by; FILE *outFile = NULL; Uint8 *buf = NULL; @@ -1270,12 +1271,14 @@ break; default: + ret = DMERR_INVALID_ARGS; dmError("Invalid output format %d, internal error.\n", outFormat); goto error; } - if (outBlockW <= 0 || outBlockH <= 0) + if (outBlockW < 1 || outBlockH < 1) { + ret = DMERR_INVALID_ARGS; dmError("Source image dimensions too small for conversion, block dimensions %d x %d.\n", outBlockW, outBlockH); goto error; @@ -1283,9 +1286,9 @@ if ((outFile = fopen(filename, "wb")) == NULL) { - int err = dmGetErrno(); + ret = dmGetErrno(); dmError("Could not open '%s' for writing, %d: %s.\n", - filename, err, dmErrorStr(err)); + filename, ret, dmErrorStr(ret)); goto error; } @@ -1308,21 +1311,27 @@ if (!dmConvertImage2Char(buf, image, bx * C64_CHR_WIDTH_PX, by * C64_CHR_HEIGHT, multicolor)) + { + ret = DMERR_DATA_ERROR; goto error; + } break; case FFMT_SPRITE: if (!dmConvertImage2Sprite(buf, image, bx * C64_SPR_WIDTH_PX, by * C64_SPR_HEIGHT, multicolor)) + { + ret = DMERR_DATA_ERROR; goto error; + } } if (!dm_fwrite_str(outFile, buf, outBufSize)) { - int err = dmGetErrno(); + ret = dmGetErrno(); dmError("Error writing data block %d,%d to '%s', %d: %s\n", - bx, by, filename, err, dmErrorStr(err)); + bx, by, filename, ret, dmErrorStr(ret)); goto error; } }