[gimp] app: use SAFE_CLAMP() in histogram bin calculation
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: use SAFE_CLAMP() in histogram bin calculation
- Date: Sun, 19 Nov 2017 12:15:06 +0000 (UTC)
commit e19958c5f15f47fd9642d77e087ab33e06e1ccd8
Author: Ell <ell_se yahoo com>
Date: Sun Nov 19 07:09:52 2017 -0500
app: use SAFE_CLAMP() in histogram bin calculation
The current code relies on undefined behavior, which, while seems
to work, is fragile. Use SAFE_CLAMP() instead.
app/core/gimphistogram.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/app/core/gimphistogram.c b/app/core/gimphistogram.c
index 7beefb4..8ae8aaa 100644
--- a/app/core/gimphistogram.c
+++ b/app/core/gimphistogram.c
@@ -238,7 +238,7 @@ gimp_histogram_calculate (GimpHistogram *histogram,
gint n_components;
gint n_bins;
gfloat n_bins_1f;
- gint temp;
+ gfloat temp;
g_return_if_fail (GIMP_IS_HISTOGRAM (histogram));
g_return_if_fail (GEGL_IS_BUFFER (buffer));
@@ -328,8 +328,11 @@ gimp_histogram_calculate (GimpHistogram *histogram,
n_bins_1f = priv->n_bins - 1;
-#define VALUE(c,i) (*(temp = SIGNED_ROUND (MIN ((i) * n_bins_1f, n_bins_1f)), \
- &priv->values[(c) * priv->n_bins + MAX (temp, 0)]))
+#define VALUE(c,i) (*(temp = (i) * n_bins_1f, \
+ &priv->values[(c) * priv->n_bins + \
+ SIGNED_ROUND (SAFE_CLAMP (temp, \
+ 0.0f, \
+ n_bins_1f))]))
while (gegl_buffer_iterator_next (iter))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]