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

matthieu castet castet.matthieu
Sun Sep 13 15:17:01 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.

This new version should fix all the comments made for previous patches.


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_longv3.diff
Type: text/x-diff
Size: 4299 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090913/df736ca3/attachment.diff>

More information about the ffmpeg-devel mailing list