Skip to content
Snippets Groups Projects
Commit 0268a996 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry Committed by Jean-Marc Valin
Browse files

Fix ectest to not check a case which isn't guaranteed to work, and which we don't use.

When I removed the special case for EC_ILOG(0) in commit
 06390d08, it broke ec_dec_uint() with _ft=1
 (which should encode the value 0 using 0 bits).
This feature was tested by ectest.c, but not actually used by libcelt.
An assert has been added to ec_dec_uint() to ensure that we don't try to use
 this feature by accident.
ec_enc_uint() was actually correct, but support for this feature has been
 removed and the assert put in its place.
parent 763abd04
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
#include <stddef.h>
#include "entdec.h"
#include "os_support.h"
#include "arch.h"
void ec_byte_readinit(ec_byte_buffer *_b,unsigned char *_buf,long _bytes){
......@@ -106,6 +107,8 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
unsigned s;
int ftb;
t=0;
/*In order to optimize EC_ILOG(), it is undefined for the value 0.*/
celt_assert(_ft>1);
_ft--;
ftb=EC_ILOG(_ft);
if(ftb>EC_UNIT_BITS){
......
......@@ -100,8 +100,10 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
unsigned ft;
unsigned fl;
int ftb;
/*In order to optimize EC_ILOG(), it is undefined for the value 0.*/
celt_assert(_ft>1);
_ft--;
ftb=EC_ILOG(_ft)&-!!_ft;
ftb=EC_ILOG(_ft);
if(ftb>EC_UNIT_BITS){
ftb-=EC_UNIT_BITS;
ft=(_ft>>ftb)+1;
......
......@@ -31,7 +31,7 @@ int main(int _argc,char **_argv){
/*Testing encoding of raw bit values.*/
ec_byte_writeinit(&buf);
ec_enc_init(&enc,&buf);
for(ft=0;ft<1024;ft++){
for(ft=2;ft<1024;ft++){
for(i=0;i<ft;i++){
entropy+=log(ft)*M_LOG2E;
ec_enc_uint(&enc,i,ft);
......@@ -59,7 +59,7 @@ int main(int _argc,char **_argv){
fprintf(stderr,"Packed to %li bytes.\n",(long)(buf.ptr-buf.buf));
ec_byte_readinit(&buf,ec_byte_get_buffer(&buf),ec_byte_bytes(&buf));
ec_dec_init(&dec,&buf);
for(ft=0;ft<1024;ft++){
for(ft=2;ft<1024;ft++){
for(i=0;i<ft;i++){
sym=ec_dec_uint(&dec,ft);
if(sym!=i){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment