Reverted some of Timothy's changes to the range decoding that were causing decode...
authorjm@0101bb08-14d6-0310-b084-bc0e0c8e3800 <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Fri, 18 Jan 2008 04:24:09 +0000 (04:24 +0000)
committerJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Fri, 18 Jan 2008 04:28:49 +0000 (15:28 +1100)
git-svn-id: http://svn.xiph.org/trunk/ghost@14413 0101bb08-14d6-0310-b084-bc0e0c8e3800

libentcode/mfrngdec.c
libentcode/rangedec.c

index 77b98e6..83571c0 100644 (file)
@@ -137,24 +137,26 @@ static int ec_dec_in(ec_dec *_this){
   int ret;
   ret=ec_byte_read1(_this->buf);
   if(ret<0){
-    long bytes;
+    unsigned char *buf;
+    long           bytes;
     bytes=ec_byte_bytes(_this->buf);
+    buf=ec_byte_get_buffer(_this->buf);
     /*Breaking abstraction: don't do this at home, kids.*/
-    if(_this->buf->storage==bytes&&bytes>0){
-      unsigned char *buf;
-      buf=ec_byte_get_buffer(_this->buf);
-      /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
-         zero, return an extra EC_FOF_RSV1 byte.*/
-      do bytes--;
-      while(bytes>0&&buf[bytes]==EC_FOF_RSV1);
-      if(!buf[bytes])ret=EC_FOF_RSV1;
+    if(_this->buf->storage==bytes){
+      ec_byte_adv1(_this->buf);
+      if(bytes>0){
+        unsigned char *p;
+        p=buf+bytes;
+        /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
+           zero, return an extra EC_FOF_RSV1 byte.*/
+        do p--;
+        while(p>buf&&p[0]==EC_FOF_RSV1);
+        if(!p[0])return EC_FOF_RSV1;
+      }
     }
-    else ret=0;
-    /*Needed to make sure the above conditional only triggers once, and to keep
-       oc_dec_tell() operating correctly.*/
-    ec_byte_adv1(_this->buf);
+    return 0;
   }
-  return ret;
+  else return ret;
 }
 
 /*Normalizes the contents of dif and rng so that rng lies entirely in the
index 49d26fd..bfe6645 100644 (file)
@@ -120,24 +120,26 @@ static int ec_dec_in(ec_dec *_this){
   int ret;
   ret=ec_byte_read1(_this->buf);
   if(ret<0){
-    long bytes;
+    unsigned char *buf;
+    long           bytes;
     bytes=ec_byte_bytes(_this->buf);
+    buf=ec_byte_get_buffer(_this->buf);
     /*Breaking abstraction: don't do this at home, kids.*/
-    if(_this->buf->storage==bytes&&bytes>0){
-      unsigned char *buf;
-      buf=ec_byte_get_buffer(_this->buf);
-      /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
-         zero, return an extra EC_FOF_RSV1 byte.*/
-      do bytes--;
-      while(bytes>0&&buf[bytes]==EC_FOF_RSV1);
-      if(!buf[bytes])ret=EC_FOF_RSV1;
+    if(_this->buf->storage==bytes){
+      ec_byte_adv1(_this->buf);
+      if(bytes>0){
+        unsigned char *p;
+        p=buf+bytes;
+        /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
+           zero, return an extra EC_FOF_RSV1 byte.*/
+        do p--;
+        while(p>buf&&p[0]==EC_FOF_RSV1);
+        if(!p[0])return EC_FOF_RSV1;
+      }
     }
-    else ret=0;
-    /*Needed to make sure the above conditional only triggers once, and to keep
-       oc_dec_tell() operating correctly.*/
-    ec_byte_adv1(_this->buf);
+    return 0;
   }
-  return ret;
+  else return ret;
 }
 
 /*Normalizes the contents of dif and rng so that rng lies entirely in the