[xiph-commits] r11748 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Mon Aug 7 23:08:54 PDT 2006


Author: jm
Date: 2006-08-07 23:08:52 -0700 (Mon, 07 Aug 2006)
New Revision: 11748

Modified:
   trunk/speex/libspeex/math_approx.c
Log:
fix potential overflow in sqrt


Modified: trunk/speex/libspeex/math_approx.c
===================================================================
--- trunk/speex/libspeex/math_approx.c	2006-08-07 13:24:09 UTC (rev 11747)
+++ trunk/speex/libspeex/math_approx.c	2006-08-08 06:08:52 UTC (rev 11748)
@@ -50,36 +50,36 @@
    int k=0;
    spx_word32_t rt;
 
-   if (x==0)
+   if (x<=0)
       return 0;
 #if 1
-   if (x>16777216)
+   if (x>=16777216)
    {
       x>>=10;
       k+=5;
    }
-   if (x>1048576)
+   if (x>=1048576)
    {
       x>>=6;
       k+=3;
    }
-   if (x>262144)
+   if (x>=262144)
    {
       x>>=4;
       k+=2;
    }
-   if (x>32768)
+   if (x>=32768)
    {
       x>>=2;
       k+=1;
    }
-   if (x>16384)
+   if (x>=16384)
    {
       x>>=2;
       k+=1;
    }
 #else
-   while (x>16384)
+   while (x>=16384)
    {
       x>>=2;
       k++;
@@ -91,6 +91,8 @@
       k--;
    }
    rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3)))))));
+   if (rt > 16383)
+      rt = 16383;
    if (k>0)
       rt <<= k;
    else



More information about the commits mailing list