[vlc-commits] vlc_bits: do not allow writing by default

Francois Cartegnie git at videolan.org
Thu Dec 3 17:34:57 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Nov 30 15:52:12 2015 +0100| [e6d44eed0c1b151f2e279801c99e3f84a7654b21] | committer: Francois Cartegnie

vlc_bits: do not allow writing by default

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e6d44eed0c1b151f2e279801c99e3f84a7654b21
---

 include/vlc_bits.h          |   15 +++++++++++++--
 modules/mux/mp4/libmp4mux.c |    2 +-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/vlc_bits.h b/include/vlc_bits.h
index 3e0478f..ed6d2ab 100644
--- a/include/vlc_bits.h
+++ b/include/vlc_bits.h
@@ -47,14 +47,22 @@ typedef struct bs_s
     uint8_t *p_end;
 
     ssize_t  i_left;    /* i_count number of available bits */
+    bool     b_read_only;
 } bs_t;
 
-static inline void bs_init( bs_t *s, const void *p_data, size_t i_data )
+static inline void bs_write_init( bs_t *s, void *p_data, size_t i_data )
 {
     s->p_start = (uint8_t *)p_data;
     s->p       = s->p_start;
     s->p_end   = s->p_start + i_data;
     s->i_left  = 8;
+    s->b_read_only = false;
+}
+
+static inline void bs_init( bs_t *s, const void *p_data, size_t i_data )
+{
+    bs_write_init( s, (void*) p_data, i_data );
+    s->b_read_only = true;
 }
 
 static inline int bs_pos( const bs_t *s )
@@ -154,6 +162,9 @@ static inline void bs_skip( bs_t *s, ssize_t i_count )
 
 static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
 {
+    if( s->b_read_only )
+        return;
+
     while( i_count > 0 )
     {
         if( s->p >= s->p_end )
@@ -199,7 +210,7 @@ static inline void bs_align_0( bs_t *s )
 
 static inline void bs_align_1( bs_t *s )
 {
-    while( s->i_left != 8 )
+    while( !s->b_read_only && s->i_left != 8 )
     {
         bs_write( s, 1, 1 );
     }
diff --git a/modules/mux/mp4/libmp4mux.c b/modules/mux/mp4/libmp4mux.c
index 7487d88..eef4883 100644
--- a/modules/mux/mp4/libmp4mux.c
+++ b/modules/mux/mp4/libmp4mux.c
@@ -298,7 +298,7 @@ static bo_t *GetDec3Tag(es_format_t *p_fmt, block_t *a52_frame)
         return NULL;
 
     bs_t s;
-    bs_init(&s, a52_frame->p_buffer, sizeof(a52_frame->i_buffer));
+    bs_write_init(&s, a52_frame->p_buffer, sizeof(a52_frame->i_buffer));
     bs_skip(&s, 16); // syncword
 
     uint8_t fscod, bsid, bsmod, acmod, lfeon, strmtyp;



More information about the vlc-commits mailing list