comparison src/libgfx.c @ 1294:9f2117f1584a

Improve error checking in PCX writer.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Aug 2017 21:35:09 +0300
parents 92e99ea23811
children 7a986f33895e
comparison
equal deleted inserted replaced
1293:1dce9e5f4a2f 1294:9f2117f1584a
932 932
933 // Write VGA palette 933 // Write VGA palette
934 if (spec->paletted) 934 if (spec->paletted)
935 { 935 {
936 int i; 936 int i;
937 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors);
938
937 dm_fwrite_byte(pcx.fp, 0x0C); 939 dm_fwrite_byte(pcx.fp, 0x0C);
938 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors);
939 940
940 for (i = 0; i < img->ncolors; i++) 941 for (i = 0; i < img->ncolors; i++)
941 { 942 {
942 dm_fwrite_byte(pcx.fp, img->pal[i].r); 943 if (!dm_fwrite_byte(pcx.fp, img->pal[i].r) ||
943 dm_fwrite_byte(pcx.fp, img->pal[i].g); 944 !dm_fwrite_byte(pcx.fp, img->pal[i].g) ||
944 dm_fwrite_byte(pcx.fp, img->pal[i].b); 945 !dm_fwrite_byte(pcx.fp, img->pal[i].b))
946 {
947 res = dmError(DMERR_FWRITE,
948 "PCX: Could not write palette data.\n");
949 goto error;
950 }
945 } 951 }
946 952
947 // Pad the palette, if necessary 953 // Pad the palette, if necessary
948 for (; i < 256; i++) 954 for (; i < 256; i++)
949 { 955 {
950 dm_fwrite_byte(pcx.fp, 0); 956 if (!dm_fwrite_byte(pcx.fp, 0) ||
951 dm_fwrite_byte(pcx.fp, 0); 957 !dm_fwrite_byte(pcx.fp, 0) ||
952 dm_fwrite_byte(pcx.fp, 0); 958 !dm_fwrite_byte(pcx.fp, 0))
959 {
960 res = dmError(DMERR_FWRITE,
961 "PCX: Could not write palette data.\n");
962 goto error;
963 }
953 } 964 }
954 } 965 }
955 966
956 error: 967 error:
957 dmFree(pcx.buf); 968 dmFree(pcx.buf);