]> granicus.if.org Git - libx264/commitdiff
Fix possible undefined behavior of right shift
authorAnton Mitrofanov <BugMaster@narod.ru>
Sun, 1 Apr 2018 17:39:30 +0000 (20:39 +0300)
committerHenrik Gramner <henrik@gramner.com>
Sun, 27 May 2018 18:58:54 +0000 (20:58 +0200)
32-bit shifts are only defined for values in the range 0-31.

common/bitstream.h

index 40ecc7adc06be1288dade2a6cffdcd265f0a387a..36698089984d6312bafffb70aa483dfee1ca18e3 100644 (file)
@@ -89,8 +89,13 @@ static inline void bs_init( bs_t *s, void *p_data, int i_data )
     s->p       = s->p_start = (uint8_t*)p_data - offset;
     s->p_end   = (uint8_t*)p_data + i_data;
     s->i_left  = (WORD_SIZE - offset)*8;
-    s->cur_bits = endian_fix32( M32(s->p) );
-    s->cur_bits >>= (4-offset)*8;
+    if( offset )
+    {
+        s->cur_bits = endian_fix32( M32(s->p) );
+        s->cur_bits >>= (4-offset)*8;
+    }
+    else
+        s->cur_bits = 0;
 }
 static inline int bs_pos( bs_t *s )
 {