diff options
author | Thomas White <taw@physics.org> | 2021-07-23 12:51:51 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-07-23 12:51:51 +0200 |
commit | f2fbc4ea79a69cfbbfc5ade73974def3efdb029b (patch) | |
tree | afc29fe9028cd821b7a220191d6dfcc7c0f4d81e /libcrystfel | |
parent | 4fbe2e349908a53032b3f23c2180a46e4f770c92 (diff) |
spectrum_get_density_at_k: Switch order of checks
The old way could potentially read beyond the bounds of the array.
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/src/spectrum.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libcrystfel/src/spectrum.c b/libcrystfel/src/spectrum.c index 91bc48c9..5f126cf0 100644 --- a/libcrystfel/src/spectrum.c +++ b/libcrystfel/src/spectrum.c @@ -162,7 +162,7 @@ double spectrum_get_density_at_k(Spectrum *s, double k) if ( k >= s->k[s->n_samples-1] ) return 0.0; /* k is definitely after the first sample, and definitely * before the last one */ - while ( (s->k[i] < k) && (i<s->n_samples) ) i++; + while ( (i<s->n_samples) && (s->k[i] < k) ) i++; assert(i < s->n_samples); frac = (k - s->k[i-1]) / (s->k[i] - s->k[i-1]); return s->pdf[i-1] + frac * (s->pdf[i] - s->pdf[i-1]); |