changeset 2463:45d863deb00b

Improve error and validity checks for external palette loading.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Apr 2020 09:11:12 +0300
parents 5ec5918c6198
children 7722c150d6de
files tools/lib64util.c
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64util.c	Thu Apr 16 09:10:47 2020 +0300
+++ b/tools/lib64util.c	Thu Apr 16 09:11:12 2020 +0300
@@ -361,13 +361,19 @@
             goto done;
         }
 
-        if (inImage->pal != NULL)
-            res = dmPaletteCopy(ppal, inImage->pal);
-        else
+        if (inImage->pixfmt != DM_PIXFMT_PALETTE)
         {
-            dmErrorMsg("Image file does not have a palette.\n");
-            res = DMERR_NULLPTR;
+            res = dmError(DMERR_INVALID_DATA,
+                "Image file is not a paletted format.\n");
         }
+
+        if (inImage->pal == NULL)
+        {
+            res = dmError(DMERR_NULLPTR,
+                "Image file does not have a palette.\n");
+        }
+
+        res = dmPaletteCopy(ppal, inImage->pal);
     }
     else
     if (dmPaletteProbeGeneric(dataBuf, dataSize, &pfmt, &index) > 0 &&
@@ -380,8 +386,8 @@
     }
     else
     {
-        res = DMERR_NOT_SUPPORTED;
-        dmErrorMsg("Not an internal palette or recognized palette file '%s'.\n",
+        res = dmError(DMERR_NOT_SUPPORTED,
+            "Not an internal palette or recognized palette file '%s'.\n",
             filename);
     }