[FFmpeg-devel] [RFC] WC3 decoder without AVPaletteControl
Reimar Döffinger
Reimar.Doeffinger
Wed Apr 15 17:29:14 CEST 2009
On Wed, Apr 15, 2009 at 04:17:24PM +0200, Michael Niedermayer wrote:
> On Sun, Apr 12, 2009 at 01:26:33PM +0200, Reimar D?ffinger wrote:
> > +int av_grow_packet(AVPacket *pkt, int grow_by)
> > +{
> > + void *new_ptr;
>
> > + if (!grow_by)
> > + return 0;
>
> for what is that good for?
Avoiding a pointless realloc in case someone does something stupid like
av_grow_packet(pkt, 0);
> > + if (pkt->size + FF_INPUT_BUFFER_PADDING_SIZE > INT_MAX - grow_by)
> > + return -1;
>
> could you write this in a way that is free of overflows please ;)
Hm. Bad "documentation", I hadn't decided what grow_by < 0 is supposed to
mean or if I should just make it unsigned (the latter I admit would not
help here).
So
> if (grow_by < 0 || pkt->size + FF_INPUT_BUFFER_PADDING_SIZE > INT_MAX - grow_by)
good enough?
I also assumed that pkt->size + FF_INPUT_BUFFER_PADDING_SIZE would not
overflow since the allocated buffer must already be that big, if you
dislike that.
> > Index: libavformat/utils.c
> > ===================================================================
> > --- libavformat/utils.c (revision 18467)
> > +++ libavformat/utils.c (working copy)
> > @@ -277,6 +277,20 @@
> > return ret;
> > }
> >
> > +int av_append_packet(ByteIOContext *s, AVPacket *pkt, int size)
> > +{
> > + int ret;
> > + int old_size;
> > + if (!pkt->size)
> > + return av_get_packet(s, pkt, size);
> > + old_size = pkt->size;
> > + ret = av_grow_packet(pkt, size);
>
> isnt av_grow_packet already checking for pkt->size==0 ?
Yes, but it only allocates a new packet then. av_get_packet also sets
pkt->pos. Sure, maybe a bit overkill for a single assignment, just
thought it might be more future-proof.
More information about the ffmpeg-devel
mailing list