[FFmpeg-devel] [PATCH v3] add put_bits_long to avoid undefined behaviour in put_bits
Michael Niedermayer
michaelni
Wed Sep 30 12:32:55 CEST 2009
On Wed, Sep 30, 2009 at 11:35:19AM +0200, Reimar D?ffinger wrote:
> Hello,
> I wanted to work on this, but...
>
> On Sun, Sep 13, 2009 at 03:17:01PM +0200, matthieu castet wrote:
> > Index: libavcodec/put_bits.h
> > ===================================================================
> > --- libavcodec/put_bits.h (r?vision 19830)
> > +++ libavcodec/put_bits.h (copie de travail)
> > @@ -143,7 +143,7 @@
> > int bit_left;
> >
> > // printf("put_bits=%d %x\n", n, value);
> > - assert(n == 32 || value < (1U << n));
> > + assert(n <= 31 && value < (1U << n));
> >
> > bit_buf = s->bit_buf;
> > bit_left = s->bit_left;
> > @@ -259,6 +259,22 @@
> > put_bits(pb, bits, val & ((1<<bits)-1));
> > }
> >
> > +static inline void put_bits_long(PutBitContext *s, int n, unsigned int value)
> > +{
> > + if(n <= 31) {
> > + put_bits(s, n, value);
> > + } else {
> > +#ifdef ALT_BITSTREAM_READER_LE
> > + put_bits(s, 16, value & 0xffff);
> > + put_bits(s, 16, value >> 16);
> > +#else
> > + put_bits(s, 16, value >> 16);
> > + put_bits(s, 16, value & 0xffff);
> > +#endif
> > + }
> > +
> > +}
>
> This only works for 0-32, and it is only used for exactly 32, so the
> questions are
> 1) do we really need a put_bits_long, or can we just do a put_bits32?
i guess a put_bits32() would do for now
> 2) if we add a put_bits_long, shouldn't it at least support up to 62
> bits? The code would almost be the same, just the argument would be
yes
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090930/78bc9235/attachment.pgp>
More information about the ffmpeg-devel
mailing list