changeset 1800:45e7688336dc

Fix checks for NULL palette in index/palette images. Also improve error messages.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 14 Jun 2018 12:42:29 +0300
parents 708d333734f9
children 0562dd55a1f6
files tools/libgfx.c
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tools/libgfx.c	Thu Jun 14 12:41:55 2018 +0300
+++ b/tools/libgfx.c	Thu Jun 14 12:42:29 2018 +0300
@@ -951,7 +951,16 @@
 
     // XXX: 24bit PCX does not work yet ..
     if (!spec.paletted)
-        return DMERR_NOT_SUPPORTED;
+    {
+        return dmError(DMERR_NOT_SUPPORTED,
+            "24bit PCX not supported yet.\n");
+    }
+
+    if (spec.paletted && img->pal == NULL)
+    {
+        return dmError(DMERR_NULLPTR,
+            "Image spec says paletted/indexed image, but palette pointer is NULL.\n");
+    }
 
     // Create output file
     pcx.buf    = NULL;
@@ -960,7 +969,7 @@
 
     // Create PCX header
     dmMemset(&hdr, 0, sizeof(hdr));
-    if (spec.paletted && img->pal != NULL)
+    if (spec.paletted)
     {
         for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++)
         {