fix bug when reading a zero-bit-long value
authorJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 12 Jul 2001 21:21:16 +0000 (21:21 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Thu, 12 Jul 2001 21:21:16 +0000 (21:21 +0000)
src/libFLAC/bitbuffer.c

index a93cfd844dd91e87bd7262463440961939e36db7..95326bf1cc41383b657c5027b7a80a4e6a7f9381 100644 (file)
@@ -1077,6 +1077,11 @@ FLAC__bool FLAC__bitbuffer_read_raw_uint32(FLAC__BitBuffer *bb, FLAC__uint32 *va
        FLAC__ASSERT(bits <= 32);
        FLAC__ASSERT((bb->capacity*8) * 2 >= bits);
 
+       if(bits == 0) {
+               *val = 0;
+               return true;
+       }
+
        while(bb->total_consumed_bits + bits > bb->total_bits) {
                if(!bitbuffer_read_from_client_(bb, read_callback, client_data))
                        return false;
@@ -1130,6 +1135,11 @@ FLAC__bool FLAC__bitbuffer_read_raw_int32(FLAC__BitBuffer *bb, FLAC__int32 *val,
 
        FLAC__ASSERT(bits <= 32);
 
+       if(bits == 0) {
+               *val = 0;
+               return true;
+       }
+
        v = 0;
        for(i = 0; i < bits; i++) {
                if(!FLAC__bitbuffer_read_bit_to_uint32(bb, &v, read_callback, client_data))
@@ -1159,6 +1169,11 @@ FLAC__bool FLAC__bitbuffer_read_raw_int32(FLAC__BitBuffer *bb, FLAC__int32 *val,
        FLAC__ASSERT(bits <= 32);
        FLAC__ASSERT((bb->capacity*8) * 2 >= bits);
 
+       if(bits == 0) {
+               *val = 0;
+               return true;
+       }
+
        while(bb->total_consumed_bits + bits > bb->total_bits) {
                if(!bitbuffer_read_from_client_(bb, read_callback, client_data))
                        return false;
@@ -1243,6 +1258,11 @@ FLAC__bool FLAC__bitbuffer_read_raw_uint64(FLAC__BitBuffer *bb, FLAC__uint64 *va
        FLAC__ASSERT(bits <= 64);
        FLAC__ASSERT((bb->capacity*8) * 2 >= bits);
 
+       if(bits == 0) {
+               *val = 0;
+               return true;
+       }
+
        while(bb->total_consumed_bits + bits > bb->total_bits) {
                if(!bitbuffer_read_from_client_(bb, read_callback, client_data))
                        return false;
@@ -1296,6 +1316,11 @@ FLAC__bool FLAC__bitbuffer_read_raw_int64(FLAC__BitBuffer *bb, FLAC__int64 *val,
 
        FLAC__ASSERT(bits <= 64);
 
+       if(bits == 0) {
+               *val = 0;
+               return true;
+       }
+
        v = 0;
        for(i = 0; i < bits; i++) {
                if(!FLAC__bitbuffer_read_bit_to_uint64(bb, &v, read_callback, client_data))
@@ -1324,6 +1349,11 @@ FLAC__bool FLAC__bitbuffer_read_raw_int64(FLAC__BitBuffer *bb, FLAC__int64 *val,
        FLAC__ASSERT(bits <= 64);
        FLAC__ASSERT((bb->capacity*8) * 2 >= bits);
 
+       if(bits == 0) {
+               *val = 0;
+               return true;
+       }
+
        while(bb->total_consumed_bits + bits > bb->total_bits) {
                if(!bitbuffer_read_from_client_(bb, read_callback, client_data))
                        return false;