[libbluray-devel] bits: avoid using too wide type

hpi1 git at videolan.org
Thu Apr 2 10:33:13 CEST 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Apr  2 11:11:26 2015 +0300| [82671ab5ace344fa0b6104563ba38aa8634a045e] | committer: hpi1

bits: avoid using too wide type

i_left is used to store values between 0 and 7.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=82671ab5ace344fa0b6104563ba38aa8634a045e
---

 src/util/bits.c |   13 ++++++-------
 src/util/bits.h |    4 ++--
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/util/bits.c b/src/util/bits.c
index fc3ec8d..01999ce 100644
--- a/src/util/bits.c
+++ b/src/util/bits.c
@@ -73,7 +73,7 @@ void bb_seek( BITBUFFER *bb, int64_t off, int whence)
     b = off >> 3;
     bb->p = &bb->p_start[b];
 
-    ssize_t i_tmp = bb->i_left - (off & 0x07);
+    int i_tmp = bb->i_left - (off & 0x07);
     if (i_tmp <= 0) {
         bb->i_left = 8 + i_tmp;
         bb->p++;
@@ -168,7 +168,7 @@ uint32_t bb_read( BITBUFFER *bb, int i_count )
 
 uint32_t bs_read( BITSTREAM *bs, int i_count )
 {
-    ssize_t left;
+    int left;
     int bytes = (i_count + 7) >> 3;
 
     if (bs->bb.p + bytes >= bs->bb.p_end) {
@@ -184,13 +184,12 @@ uint32_t bs_read( BITSTREAM *bs, int i_count )
 
 void bb_skip( BITBUFFER *bb, size_t i_count )
 {
-    bb->i_left -= i_count;
+    bb->p += i_count >> 3;
+    bb->i_left -= i_count & 0x07;
 
     if( bb->i_left <= 0 ) {
-        const int i_bytes = ( -bb->i_left + 8 ) / 8;
-
-        bb->p += i_bytes;
-        bb->i_left += 8 * i_bytes;
+        bb->p++;
+        bb->i_left += 8;
     }
 }
 
diff --git a/src/util/bits.h b/src/util/bits.h
index 2ba2114..e33c625 100644
--- a/src/util/bits.h
+++ b/src/util/bits.h
@@ -28,7 +28,7 @@
 
 #include <stdint.h>
 #include <stdio.h>     // SEEK_*
-#include <sys/types.h> // *size_t
+#include <stddef.h>    // size_t
 
 
 /**
@@ -43,7 +43,7 @@ typedef struct {
     const uint8_t *p;
     const uint8_t *p_end;
 
-    ssize_t  i_left;    /* i_count number of available bits */
+    int            i_left;    /* i_count number of available bits */
 } BITBUFFER;
 
 typedef struct {



More information about the libbluray-devel mailing list