Additional safety net to prevent NaNs in the encoder from causing a segfault
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Tue, 19 Jun 2007 03:31:27 +0000 (03:31 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Tue, 19 Jun 2007 03:31:27 +0000 (03:31 +0000)
(as had happened with vorbis-psy)

git-svn-id: http://svn.xiph.org/trunk/speex@13141 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/cb_search.c

index cab2b71..a0b668a 100644 (file)
@@ -359,7 +359,11 @@ int   update_target
       /*"erase" nbest list*/
       for (j=0;j<N;j++)
          ndist[j]=VERY_LARGE32;
-
+      /* This is not strictly necessary, but it provides an additonal safety 
+         to prevent crashes in case something goes wrong in the previous
+         steps (e.g. NaNs) */
+      for (j=0;j<N;j++)
+         best_nind[j] = best_ntarget[j] = 0;
       /*For all n-bests of previous subvector*/
       for (j=0;j<N;j++)
       {
@@ -397,6 +401,7 @@ int   update_target
                         best_nind[n] = best_nind[n-1];
                         best_ntarget[n] = best_ntarget[n-1];
                      }
+                     /* n is equal to m here, so they're interchangeable */
                      ndist[m] = err;
                      best_nind[n] = best_index[k];
                      best_ntarget[n] = j;