Add additional check when attempting to encode values through
authorMonty <xiphmont@xiph.org>
Fri, 22 Jun 2007 03:01:47 +0000 (03:01 +0000)
committerMonty <xiphmont@xiph.org>
Fri, 22 Jun 2007 03:01:47 +0000 (03:01 +0000)
codebooks with no entries.  Ideally that wouldn't happen, but it looks
like the automated codebook training ended up with a few 'null' books.

svn path=/trunk/vorbis/; revision=13169

lib/codebook.c
lib/info.c
lib/res0.c

index ea36032..e689756 100644 (file)
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.39 2002/06/28 22:19:35 xiphmont Exp $
+ last mod: $Id$
 
  ********************************************************************/
 
@@ -255,6 +255,7 @@ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
 
 /* returns the number of bits ************************************************/
 int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
+  if(a<0 || a>=book->c->entries)return(0);
   oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
   return(book->c->lengthlist[a]);
 }
index 61b3792..f6cf568 100644 (file)
@@ -425,7 +425,7 @@ static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
 }
 
 static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
-  char temp[]="Xiph.Org libVorbis I 20070621";
+  char temp[]="Xiph.Org libVorbis I 20070622";
   int bytes = strlen(temp);
 
   /* preamble */  
index 5720bac..8a78981 100644 (file)
@@ -336,7 +336,7 @@ static int local_book_besterror(codebook *book,float *a){
     }
   }
 
-  {
+  if(best>-1){
     float *ptr=book->valuelist+best*dim;
     for(i=0;i<dim;i++)
       *a++ -= *ptr++;
@@ -355,10 +355,12 @@ static int _encodepart(oggpack_buffer *opb,float *vec, int n,
     int entry=local_book_besterror(book,vec+i*dim);
 
 #ifdef TRAIN_RES
-    acc[entry]++;
+    if(entry>0)
+      acc[entry]++;
 #endif
-
+      
     bits+=vorbis_book_encode(book,entry,opb);
+  
   }
 
   return(bits);