public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* [Fwd: gsl-1.5: possible bug under interpolation/accel.c module]
@ 2005-05-13 21:18 Gerard Jungman
  0 siblings, 0 replies; only message in thread
From: Gerard Jungman @ 2005-05-13 21:18 UTC (permalink / raw)
  To: gsl-discuss

[-- Attachment #1: Type: text/plain, Size: 70 bytes --]


-- 
Gerard Jungman <jungman@lanl.gov>
Los Alamos National Laboratory

[-- Attachment #2: Forwarded message - gsl-1.5: possible bug under interpolation/accel.c module --]
[-- Type: message/rfc822, Size: 3524 bytes --]

From: Paolo Montegriffo <paolo.montegriffo@bo.astro.it>
To: jungman@lanl.gov
Subject: gsl-1.5: possible bug under interpolation/accel.c module
Date: Wed, 11 May 2005 10:16:09 +0200
Message-ID: <4281BF49.2010306@bo.astro.it>

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





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-05-13 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-13 21:18 [Fwd: gsl-1.5: possible bug under interpolation/accel.c module] Gerard Jungman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).