aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-09-22 21:48:21 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-09-22 21:48:21 +0200
commit88a6e495154f72127f208455f40201d3e17e423a (patch)
tree751e72b8d78f807d97ad8ffde9349baf1c079b12
parent01bcfc5d692236bffeec5b8de2c27138e71d2bd6 (diff)
downloadtoolame-dab-88a6e495154f72127f208455f40201d3e17e423a.tar.gz
toolame-dab-88a6e495154f72127f208455f40201d3e17e423a.tar.bz2
toolame-dab-88a6e495154f72127f208455f40201d3e17e423a.zip
Repair PSY model 2 and 4
Fix an undefined behaviour arising when a float infinite is casted to an int.
-rw-r--r--fft.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/fft.c b/fft.c
index 87a89c8..b335a47 100644
--- a/fft.c
+++ b/fft.c
@@ -1191,8 +1191,16 @@ static void fht (FLOAT * fz)
INLINE FLOAT atan_table(FLOAT y, FLOAT x) {
int index;
+ double index_d = ATANSCALE * fabs(y/x);
+
+ // Don't cast an infinite to an int, that's undefined behaviour
+ if (isfinite(index_d)) {
+ index = (int)(ATANSCALE * fabs(y/x));
+ }
+ else {
+ index = ATANSIZE-1;
+ }
- index = (int)(ATANSCALE * fabs(y/x));
if (index>=ATANSIZE)
index = ATANSIZE-1;