[x264-devel] Fix possible undefined behavior of right shift

Anton Mitrofanov git at videolan.org
Tue Aug 7 00:05:18 CEST 2018


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Sun Apr  1 20:39:30 2018 +0300| [da6b29b553bb56e16e99527733849735c2ea264c] | committer: Henrik Gramner

Fix possible undefined behavior of right shift

32-bit shifts are only defined for values in the range 0-31.

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

 common/bitstream.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/common/bitstream.h b/common/bitstream.h
index 40ecc7ad..36698089 100644
--- a/common/bitstream.h
+++ b/common/bitstream.h
@@ -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 )
 {



More information about the x264-devel mailing list