Fix the bug that was causing the last byte of the stream to be returned incorrectly, as well as undo jm's reversion, which can cause ec_dec_tell() to operate incorrectly at the end of the stream.

A few other minor updates are included as well.

git-svn-id: http://svn.xiph.org/trunk/ghost@14427 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
tterribe 2008-01-23 23:04:43 +00:00 committed by Jean-Marc Valin
parent 77ff83a28c
commit 7e3293f713
5 changed files with 85 additions and 55 deletions

View file

@ -110,6 +110,7 @@
}*/
#include <stdio.h>
/*Gets the next byte of input.
After all the bytes in the current packet have been consumed, and the extra
@ -121,25 +122,26 @@ static int ec_dec_in(ec_dec *_this){
ret=ec_byte_read1(_this->buf);
if(ret<0){
unsigned char *buf;
long bytes;
bytes=ec_byte_bytes(_this->buf);
long i;
i=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){
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;
}
if(_this->buf->storage==i&&i>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 i--;
while(i>0&&buf[i]==EC_FOF_RSV1);
if(!buf[i])ret=EC_FOF_RSV1;
else ret=0;
}
return 0;
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);
}
else return ret;
return ret;
}
/*Normalizes the contents of dif and rng so that rng lies entirely in the