[DVDnav-discuss] [PATCH] libdvdread: Fix crash when PTT is too short

Frédéric Marchal fmarchal at perso.be
Mon Jul 11 05:40:53 CEST 2011


On Sunday 10 July 2011 11:38:11 Mirek Jezbera wrote:
> Hi Dominik,
> > I assume that sizeof(uint32_t) comes from a few lines above:
> > 
> > data = (uint32_t *)malloc(info_length);
> > 
> > Why not use sizeof(*data)?
> 
> Are you sure, that sizeof can determine size of memory allocated with
> malloc? I think it can return size of statically allocated structures and
> base types.

Just to keep track of the answer: malloc cannot determine the size of a 
dynamically allocated object but that's not the purpose. sizeof(*data) returns 
the size of one item pointed by data. It could be written as sizeof(data[0]).

It is computed at compile time and doesn't even require that data points to a 
valid memory. sizeof(*data) will work even if data is NULL or invalid. 

And for the record, sizeof(Data) is the size of a pointer. It is not the size 
of the allocated memory.

Frederic


More information about the DVDnav-discuss mailing list