shithub: opus

Download patch

ref: 68b8d72e6a252e8df691b8ef7d458e256f7b7268
parent: 495114b755d157f45a48bb8304d9d7f2f9f2bd91
author: Timothy B. Terriberry <[email protected]>
date: Mon Jan 24 07:50:30 EST 2011

Fix off-by-one error in ec_laplace_encode.

di_max was counting the _number_ of code-points remaining, not the
 largest one that could be used.

--- a/libcelt/laplace.c
+++ b/libcelt/laplace.c
@@ -75,10 +75,10 @@
       if (fs <= 0)
       {
          int di;
-         int di_max;
-         di_max = (32768-fl+LAPLACE_MINP-1)>>LAPLACE_LOG_MINP;
-         di_max = (di_max-s)>>1;
-         di = IMIN(val - i, di_max);
+         int ndi_max;
+         ndi_max = (32768-fl+LAPLACE_MINP-1)>>LAPLACE_LOG_MINP;
+         ndi_max = (ndi_max-s)>>1;
+         di = IMIN(val - i, ndi_max - 1);
          fl += (2*di+1+s)*LAPLACE_MINP;
          fs = IMIN(LAPLACE_MINP, 32768-fl);
          *value = i+di+s^s;