[gimp] 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] Issue #5008: Always true condition (i>=0) inside fill_inverse_cmap_gray.
- Date: Sat, 24 Apr 2021 12:51:03 +0000 (UTC)
commit d6dac255790d6004a3df0fa93f6fc7bbdbf3d3d6
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.
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 60f65abbc9..3295863d95 100644
--- a/app/core/gimpimage-convert-indexed.c
+++ b/app/core/gimpimage-convert-indexed.c
@@ -2692,7 +2692,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++)
@@ -2703,11 +2705,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]