[FFmpeg-devel] [PATCH] add put_bits_long to avoid undefined behaviour in put_bits

matthieu castet castet.matthieu
Sat Aug 22 22:22:19 CEST 2009


the put_bits can be called with
	unsigned int bit_buf = 0;
	int bit_left = 32;
	int n = 32;
	unsigned int value = 0x1ba;

in the case of ALT_BITSTREAM_WRITER and BITSTREAM_WRITER_LE is not defined, we
will do "bit_buf<<=bit_left;"
But sizeof(bit_buf) == 32 and bit_left==32, and we are in a undefined 

This patch add a put_bits_long for n = 32 and restrict n <= 31 for put_bits.


PS : this should fix fate for llvm

[1] C99 standard, ?6.5.7
If the value of the right operand is negative or is
greater than or equal to the width of the promoted 
left operand, the behavior is undefined.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: put_bits_long.diff
Type: text/x-diff
Size: 4268 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090822/2eeabaf8/attachment.diff>

More information about the ffmpeg-devel mailing list