[gimp/gimp-2-10] Issue #5008: Always true condition (i>=0) inside fill_inverse_cmap_gray.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] Issue #5008: Always true condition (i>=0) inside fill_inverse_cmap_gray.
- Date: Sat, 24 Apr 2021 13:27:05 +0000 (UTC)
commit ac7e841e241c553371550d4604bd850406f018b6
Author: Jehan <jehan girinstud io>
Date: Sat Apr 24 14:43:43 2021 +0200
Issue #5008: Always true condition (i>=0) inside fill_inverse_cmap_gray.
Removing useless condition, add a g_return_if_fail() assertion for the
only (impossible unless bug) case which we don't expect. Also set
default mindist to G_MAXLONG instead of a magic number (which was ok now
but might become a problem if some day colormap allowed more than 16-bit
per channel colors).
Finally break when we reach a distance of 0 since we won't get lower
anyway, so better stop early.
Thanks to Rafał Mikrut and Øyvind Kolås for code commenting.
(cherry picked from commit d6dac255790d6004a3df0fa93f6fc7bbdbf3d3d6)
app/core/gimpimage-convert-indexed.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/app/core/gimpimage-convert-indexed.c b/app/core/gimpimage-convert-indexed.c
index 89347a7bb9..3ba9d19bf9 100644
--- a/app/core/gimpimage-convert-indexed.c
+++ b/app/core/gimpimage-convert-indexed.c
@@ -2688,7 +2688,9 @@ fill_inverse_cmap_gray (QuantizeObj *quantobj,
gint mindisti;
gint i;
- mindist = 65536;
+ g_return_if_fail (quantobj->actual_number_of_colors > 0);
+
+ mindist = G_MAXLONG;
mindisti = -1;
for (i = 0; i < quantobj->actual_number_of_colors; i++)
@@ -2699,11 +2701,13 @@ fill_inverse_cmap_gray (QuantizeObj *quantobj,
{
mindist = dist;
mindisti = i;
+
+ if (mindist == 0)
+ break;
}
}
- if (i >= 0)
- histogram[pixel] = mindisti + 1;
+ histogram[pixel] = mindisti + 1;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]