--- Begin Message ---
- From: Paolo Montegriffo <paolo dot montegriffo at bo dot astro dot it>
- To: jungman at lanl dot gov
- Date: Wed, 11 May 2005 10:16:09 +0200
- Subject: gsl-1.5: possible bug under interpolation/accel.c module
- Organization: Bologna Astronomical Observatory
Hi
I was looking at interpolation/accel.c module grom gsl lib - version 1.5
when I noted a possible bug
in function gsl_interp_accel_find() here reported:
size_t
gsl_interp_accel_find (gsl_interp_accel * a, const double xa[], size_t
len, doub
le x)
{
size_t x_index = a->cache;
if (x < xa[x_index])
{
a->miss_count++;
a->cache = gsl_interp_bsearch (xa, x, 0, x_index);
}
else if (x > xa[x_index + 1])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I think that here you should first test wether x_index < len - 1 to
avoid undefined behaviour
else if (x_index < len - 1 && x > xa[x_index + 1])
{
a->miss_count++;
a->cache = gsl_interp_bsearch (xa, x, x_index, len - 1);
}
else
{
a->hit_count++;
}
return a->cache;
}
in this way if a_cache = len - 1 and x >= xa[len-1] the function
correctly return (len - 1) and the
cached value is left unchanged
hope this helps
cheers
Paolo Montegriffo
INAF - Bologna Astronomical Observatory
Via Ranzani, 1 I-40127 Bologna
Italy
--- End Message ---