Mercurial > hg > dmlib
changeset 1294:9f2117f1584a
Improve error checking in PCX writer.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 18 Aug 2017 21:35:09 +0300 |
parents | 1dce9e5f4a2f |
children | 7a986f33895e |
files | src/libgfx.c |
diffstat | 1 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/libgfx.c Fri Aug 18 20:04:31 2017 +0300 +++ b/src/libgfx.c Fri Aug 18 21:35:09 2017 +0300 @@ -934,22 +934,33 @@ if (spec->paletted) { int i; + dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors); + dm_fwrite_byte(pcx.fp, 0x0C); - dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors); for (i = 0; i < img->ncolors; i++) { - dm_fwrite_byte(pcx.fp, img->pal[i].r); - dm_fwrite_byte(pcx.fp, img->pal[i].g); - dm_fwrite_byte(pcx.fp, img->pal[i].b); + if (!dm_fwrite_byte(pcx.fp, img->pal[i].r) || + !dm_fwrite_byte(pcx.fp, img->pal[i].g) || + !dm_fwrite_byte(pcx.fp, img->pal[i].b)) + { + res = dmError(DMERR_FWRITE, + "PCX: Could not write palette data.\n"); + goto error; + } } // Pad the palette, if necessary for (; i < 256; i++) { - dm_fwrite_byte(pcx.fp, 0); - dm_fwrite_byte(pcx.fp, 0); - dm_fwrite_byte(pcx.fp, 0); + if (!dm_fwrite_byte(pcx.fp, 0) || + !dm_fwrite_byte(pcx.fp, 0) || + !dm_fwrite_byte(pcx.fp, 0)) + { + res = dmError(DMERR_FWRITE, + "PCX: Could not write palette data.\n"); + goto error; + } } }