diff options
author | tlatorre <tlatorre@uchicago.edu> | 2018-09-18 18:04:52 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2018-09-18 18:04:52 -0500 |
commit | 5938f05b8fc5feef6f823a51c977b4f0cf51050f (patch) | |
tree | 73c0ba3eefa5ad3cd8843f9551a5cb25c1f72656 /src/misc.c | |
parent | f865d2303b4ac82dca2680626ae94c26efe63450 (diff) | |
download | sddm-5938f05b8fc5feef6f823a51c977b4f0cf51050f.tar.gz sddm-5938f05b8fc5feef6f823a51c977b4f0cf51050f.tar.bz2 sddm-5938f05b8fc5feef6f823a51c977b4f0cf51050f.zip |
fix heap overflow in interp1d()
This commit fixes a potential heap overflow in interp1d() which could occur if
x was very close to the last value in the xp array. The bounds check is now
performed on the index rather than the x values.
Diffstat (limited to 'src/misc.c')
-rw-r--r-- | src/misc.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -327,10 +327,11 @@ double interp1d(double x, double *xp, double *yp, size_t n) size_t i; if (x <= xp[0]) return yp[0]; - if (x >= xp[n-1]) return yp[n-1]; i = (x-xp[0])/(xp[1]-xp[0]); + if (i > n-2) return yp[n-1]; + return yp[i] + (yp[i+1]-yp[i])*(x-xp[i])/(xp[i+1]-xp[i]); } |