Commit e19958c5 authored by Ell's avatar Ell

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.
parent e9f45798
......@@ -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))
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment