comparison tools/lib64util.c @ 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 5ffc48a0bebe
children a40de347fcb0
comparison
equal deleted inserted replaced
2462:5ec5918c6198 2463:45d863deb00b
359 dmErrorMsg("Could not read image file: %s\n", 359 dmErrorMsg("Could not read image file: %s\n",
360 dmErrorStr(res)); 360 dmErrorStr(res));
361 goto done; 361 goto done;
362 } 362 }
363 363
364 if (inImage->pal != NULL) 364 if (inImage->pixfmt != DM_PIXFMT_PALETTE)
365 res = dmPaletteCopy(ppal, inImage->pal); 365 {
366 else 366 res = dmError(DMERR_INVALID_DATA,
367 { 367 "Image file is not a paletted format.\n");
368 dmErrorMsg("Image file does not have a palette.\n"); 368 }
369 res = DMERR_NULLPTR; 369
370 } 370 if (inImage->pal == NULL)
371 {
372 res = dmError(DMERR_NULLPTR,
373 "Image file does not have a palette.\n");
374 }
375
376 res = dmPaletteCopy(ppal, inImage->pal);
371 } 377 }
372 else 378 else
373 if (dmPaletteProbeGeneric(dataBuf, dataSize, &pfmt, &index) > 0 && 379 if (dmPaletteProbeGeneric(dataBuf, dataSize, &pfmt, &index) > 0 &&
374 pfmt->read != NULL) 380 pfmt->read != NULL)
375 { 381 {
378 384
379 res = pfmt->read(fh, ppal); 385 res = pfmt->read(fh, ppal);
380 } 386 }
381 else 387 else
382 { 388 {
383 res = DMERR_NOT_SUPPORTED; 389 res = dmError(DMERR_NOT_SUPPORTED,
384 dmErrorMsg("Not an internal palette or recognized palette file '%s'.\n", 390 "Not an internal palette or recognized palette file '%s'.\n",
385 filename); 391 filename);
386 } 392 }
387 393
388 done: 394 done:
389 dmf_close(fh); 395 dmf_close(fh);