From 32336a2350b24d9187c8ceed20a95b405ed02b38 Mon Sep 17 00:00:00 2001 From: Simon Budig Date: Sun, 5 May 2024 23:56:09 +0200 Subject: [PATCH] app: avoid uninitialized memory for color names --- app/core/gimpimage-colormap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c index 93f229b31a..57a5604570 100644 --- a/app/core/gimpimage-colormap.c +++ b/app/core/gimpimage-colormap.c @@ -532,14 +532,18 @@ gimp_image_colormap_set_palette_entry (GimpImage *image, const Babl *format; guint8 rgb[3]; gchar name[64]; + gint i; g_return_if_fail (GEGL_IS_COLOR (color)); /* Adding black entries if needed. */ - while (gimp_palette_get_n_colors (private->palette) <= index) - gimp_palette_add_entry (private->palette, index, name, new_color); - - g_snprintf (name, sizeof (name), "#%d", index); + for (i = gimp_palette_get_n_colors (private->palette); + i <= index; + i++) + { + g_snprintf (name, sizeof (name), "#%d", i); + gimp_palette_add_entry (private->palette, index, name, new_color); + } space = gimp_image_get_layer_space (image); format = gimp_babl_format (GIMP_RGB, private->precision, FALSE, space);