# HG changeset patch # User Matti Hamalainen # Date 1503081309 -10800 # Node ID 9f2117f1584a5507c2711b795551ab7bb31eb7e8 # Parent 1dce9e5f4a2fc1be0472a60e69641c0f05b50e6f Improve error checking in PCX writer. diff -r 1dce9e5f4a2f -r 9f2117f1584a src/libgfx.c --- 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; + } } }