From: Anton Mitrofanov Date: Sun, 1 Apr 2018 17:39:30 +0000 (+0300) Subject: Fix possible undefined behavior of right shift X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da6b29b553bb56e16e99527733849735c2ea264c;p=libx264 Fix possible undefined behavior of right shift 32-bit shifts are only defined for values in the range 0-31. --- 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 ) {