Reason of REALLOC implementation ?

John Tytgat John.Tytgat at aaug.net
Mon Apr 16 00:23:52 BST 2007


In message <E1HdD3W-000JWi-NT at pr-webmail-2.demon.net> you wrote:

>    John.Tytgat at aaug.net wrote:
> > When you make an existing malloc block bigger, the old ptr gets used
> > to read the new size 'size' from and this can lead to undefined behaviour.
> 
>    But that doesn't matter, because it was only written for a specific reason where I knew the behaviour was OK. (It can read off the end of memory, but RISC OS didn't do anything bad then. This back in the days of "address exception"---no segfaults!). So the bug is that it says "portable" in the comment---it's actually RISC OS-specific.

A bit scary given that it is now also used in cross-compilation situations.
I've removed it on the simplified-build branch and will see if this breaks
something or not.

> > Also when the first malloc() call above fails, there is no free() of the
> > old pointer done...
> 
>    That's actually what the spec says. To do the opposite would destroy the caller's data.

True. I was wrong on that.

Thanks,
John.
-- 
John Tytgat, in his comfy chair at home                                 BASS
John.Tytgat at aaug.net                             ARM powered, RISC OS driven



More information about the oslib-team mailing list