This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fwd: gsl-1.5: possible bug under interpolation/accel.c module]


-- 
Gerard Jungman <jungman@lanl.gov>
Los Alamos National Laboratory
--- Begin Message --- 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 ---

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]