[gimp] app: fix a crash in PDB "gimp-image-get-colormap".
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: fix a crash in PDB "gimp-image-get-colormap".
- Date: Sat, 12 Mar 2022 17:55:49 +0000 (UTC)
commit f90efdf9d6dcf950aae279aa8bbd551f6c04d214
Author: Jehan <jehan girinstud io>
Date: Sat Mar 12 18:05:07 2022 +0100
app: fix a crash in PDB "gimp-image-get-colormap".
In case we have a palette on an image which is empty, don't return a
colormap together with a size 0, just return NULL.
app/core/gimpimage-colormap.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c
index b880b6b552..7843a1235d 100644
--- a/app/core/gimpimage-colormap.c
+++ b/app/core/gimpimage-colormap.c
@@ -235,7 +235,7 @@ guchar *
gimp_image_get_colormap (GimpImage *image)
{
GimpImagePrivate *private;
- guchar *colormap;
+ guchar *colormap = NULL;
gint n_colors, i;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
@@ -245,15 +245,19 @@ gimp_image_get_colormap (GimpImage *image)
return NULL;
n_colors = gimp_palette_get_n_colors (private->palette);
- colormap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);
- for (i = 0; i < n_colors; i++)
+ if (n_colors > 0)
{
- GimpPaletteEntry *entry = gimp_palette_get_entry (private->palette, i);
- gimp_rgb_get_uchar (&entry->color,
- &colormap[i * 3],
- &colormap[i * 3 + 1],
- &colormap[i * 3 + 2]);
+ colormap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);
+
+ for (i = 0; i < n_colors; i++)
+ {
+ GimpPaletteEntry *entry = gimp_palette_get_entry (private->palette, i);
+ gimp_rgb_get_uchar (&entry->color,
+ &colormap[i * 3],
+ &colormap[i * 3 + 1],
+ &colormap[i * 3 + 2]);
+ }
}
return colormap;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]