shithub: opus

Download patch

ref: d84fa9fd6eb96202f5721ae3ce6410d1cbb19f96
parent: aecf2d3eff93a1152ab2bd7012bdeefa0583ef0e
author: Gregory Maxwell <[email protected]>
date: Fri Oct 28 07:06:37 EDT 2011

Fixes a bug in ec_enc_done when no range coded data was coded and adds test cases to test_unit_entropy.

--- a/celt/entenc.c
+++ b/celt/entenc.c
@@ -287,8 +287,8 @@
           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;
     }
   }
 }
--- a/celt/tests/test_unit_entropy.c
+++ b/celt/tests/test_unit_entropy.c
@@ -326,6 +326,25 @@
     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;
 }