[MPlayer-dev-eng] [PATCH] Movie fragments support for demux_mov

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Jan 6 22:06:14 CET 2008


Hello,
On Sun, Jan 06, 2008 at 12:27:39PM +0100, David Romacho wrote:
> Reimar Döffinger wrote:
> >> +    // Add chunks
> >> +    trak->chunks = realloc_struct(trak->chunks, trak->chunks_size+traf->chunks_size, sizeof(mov_chunk_t));
> >> +    memcpy( &trak->chunks[trak->chunks_size], traf->chunks, traf->chunks_size*sizeof( mov_chunk_t ) );
> >> +    trak->chunks_size += traf->chunks_size;
> >>     
> >
> > Hm.. I think this code may need an integer overflow check for the
> > trak->chunks_size+traf->chunks_size and possibly a != NULL check for the
> > trak->chunks after realloc to be safe...
> > Possibly there is no problem since the values are limited in size so no
> > overflow can happen, in this case a comment would probably be good.
> >
> >   
> How can I check an integer overflow, would that be enough:
> 
> if((trak->chunks_size+traf->chunks_size < trak->chunk_size)||(trak->chunks_size+traf->chunks_size < traf->chunk_size)) // overflow occured
> 
> 
> Is there any nicer way to do that?

Just
if (trak->chunks_size + traf->chunks_size < trak->chunks_size)
should (usually) be enough, assuming you use realloc_struct and check
the return value.

Greetings,
Reimar Döffinger



More information about the MPlayer-dev-eng mailing list