diff options
-rw-r--r-- | libcelt/cwrs.c | 30 | ||||
-rw-r--r-- | libcelt/mathops.h | 1 | ||||
-rw-r--r-- | tests/cwrs32-test.c | 2 | ||||
-rw-r--r-- | tests/cwrs64-test.c | 2 |
4 files changed, 21 insertions, 14 deletions
diff --git a/libcelt/cwrs.c b/libcelt/cwrs.c index c8a2ac6..91a1732 100644 --- a/libcelt/cwrs.c +++ b/libcelt/cwrs.c @@ -54,22 +54,24 @@ static inline void unext32(celt_uint32_t *_ui,int _len,celt_uint32_t _ui0){ celt_uint32_t ui1; int j; - for(j=1;j<_len;j++){ + /* doing a do-while would overrun the array if we had less than 2 samples */ + j=1; do { ui1=_ui[j]+_ui[j-1]+_ui0; _ui[j-1]=_ui0; _ui0=ui1; - } + } while (++j<_len); _ui[j-1]=_ui0; } static inline void unext64(celt_uint64_t *_ui,int _len,celt_uint64_t _ui0){ celt_uint64_t ui1; int j; - for(j=1;j<_len;j++){ + /* doing a do-while would overrun the array if we had less than 2 samples */ + j=1; do { ui1=_ui[j]+_ui[j-1]+_ui0; _ui[j-1]=_ui0; _ui0=ui1; - } + } while (++j<_len); _ui[j-1]=_ui0; } @@ -79,22 +81,24 @@ static inline void unext64(celt_uint64_t *_ui,int _len,celt_uint64_t _ui0){ static inline void uprev32(celt_uint32_t *_ui,int _n,celt_uint32_t _ui0){ celt_uint32_t ui1; int j; - for(j=1;j<_n;j++){ + /* doing a do-while would overrun the array if we had less than 2 samples */ + j=1; do { ui1=_ui[j]-_ui[j-1]-_ui0; _ui[j-1]=_ui0; _ui0=ui1; - } + } while (++j<_n); _ui[j-1]=_ui0; } static inline void uprev64(celt_uint64_t *_ui,int _n,celt_uint64_t _ui0){ celt_uint64_t ui1; int j; - for(j=1;j<_n;j++){ + /* doing a do-while would overrun the array if we had less than 2 samples */ + j=1; do { ui1=_ui[j]-_ui[j-1]-_ui0; _ui[j-1]=_ui0; _ui0=ui1; - } + } while (++j<_n); _ui[j-1]=_ui0; } @@ -108,12 +112,13 @@ celt_uint32_t ncwrs_unext32(int _n,celt_uint32_t *_ui){ celt_uint32_t ui1; int j; ret=ui0=2; - for(j=1;j<_n;j++){ + celt_assert(_n>=2); + j=1; do { ui1=_ui[j]+_ui[j-1]+ui0; _ui[j-1]=ui0; ui0=ui1; ret+=ui0; - } + } while (++j<_n); _ui[j-1]=ui0; return ret; } @@ -124,12 +129,13 @@ celt_uint64_t ncwrs_unext64(int _n,celt_uint64_t *_ui){ celt_uint64_t ui1; int j; ret=ui0=2; - for(j=1;j<_n;j++){ + celt_assert(_n>=2); + j=1; do { ui1=_ui[j]+_ui[j-1]+ui0; _ui[j-1]=ui0; ui0=ui1; ret+=ui0; - } + } while (++j<_n); _ui[j-1]=ui0; return ret; } diff --git a/libcelt/mathops.h b/libcelt/mathops.h index dc3f741..22588cd 100644 --- a/libcelt/mathops.h +++ b/libcelt/mathops.h @@ -37,6 +37,7 @@ #include "arch.h" #include "entcode.h" +#include "os_support.h" #ifndef OVERRIDE_CELT_ILOG2 /** Integer log in base2. Undefined for zero and negative numbers */ diff --git a/tests/cwrs32-test.c b/tests/cwrs32-test.c index 1f10ed4..8285fb4 100644 --- a/tests/cwrs32-test.c +++ b/tests/cwrs32-test.c @@ -10,7 +10,7 @@ int main(int _argc,char **_argv){ int n; - for(n=0;n<=NMAX;n++){ + for(n=2;n<=NMAX;n++){ int m; for(m=0;m<=MMAX;m++){ celt_uint32_t uu[NMAX]; diff --git a/tests/cwrs64-test.c b/tests/cwrs64-test.c index 2878f28..b0c79b5 100644 --- a/tests/cwrs64-test.c +++ b/tests/cwrs64-test.c @@ -11,7 +11,7 @@ int main(int _argc,char **_argv){ int n; - for(n=0;n<=NMAX;n+=3){ + for(n=2;n<=NMAX;n+=3){ int m; for(m=0;m<=MMAX;m++){ celt_uint64_t uu[NMAX]; |