Fixes a bug in ec_enc_done when no range coded data was coded and adds test cases...
authorGregory Maxwell <greg@xiph.org>
Fri, 28 Oct 2011 15:06:37 +0000 (11:06 -0400)
committerGregory Maxwell <greg@xiph.org>
Fri, 28 Oct 2011 15:08:52 +0000 (11:08 -0400)
celt/entenc.c
celt/tests/test_unit_entropy.c

index 2e20c35..3913d8e 100644 (file)
@@ -287,8 +287,8 @@ void ec_enc_done(ec_enc *_this){
           window&=(1<<l)-1;
           _this->error=-1;
         }
+        _this->buf[_this->storage-_this->end_offs-1]|=(unsigned char)window;
       }
-      _this->buf[_this->storage-_this->end_offs-1]|=(unsigned char)window;
     }
   }
 }
index 982722c..a1ff668 100644 (file)
@@ -326,6 +326,25 @@ int main(int _argc,char **_argv){
     fprintf(stderr,"Got %d when expecting 63 for patch_initial_bits",ptr[0]);
     ret=-1;
   }
+  ec_enc_init(&enc,ptr,2);
+  ec_enc_bit_logp(&enc,0,2);
+  for(i=0;i<48;i++){
+    ec_enc_bits(&enc,0,1);
+  }
+  ec_enc_done(&enc);
+  if(!enc.error){
+    fprintf(stderr,"Raw bits overfill didn't fail when it should have");
+    ret=-1;
+  }
+  ec_enc_init(&enc,ptr,2);
+  for(i=0;i<17;i++){
+    ec_enc_bits(&enc,0,1);
+  }
+  ec_enc_done(&enc);
+  if(!enc.error){
+    fprintf(stderr,"17 raw bits encoded in two bytes");
+    ret=-1;
+  }
   free(ptr);
   return ret;
 }