Reason of REALLOC implementation ?
Stewart Brodie
stewart at metahusky.net
Mon Apr 16 00:14:30 BST 2007
jonathan at doves.demon.co.uk wrote:
> John.Tytgat at aaug.net wrote:
>
> > In !OsLib/Tools/support there are two files realloc.c and realloc.h
which
> > implement the REALLOC() function. The file
!OsLib/Tools/support/doc/realloc
> > says:
> >
> > --8<--
> > realloc.c
> > ---------
> >
> > Just a portable realloc with no bugs. It's called REALLOC, though.
> > --8<--
> >
> > Does someone know which bugs (and in which component) this document
> > refers too ? Bugs in a cross compiled environment ? Or bugs in RISC OS
SCL ?
>
> Well, vaguely ...
>
> It was SharedCLib, but I don't remember the precise problem. It may
have been something to do with the fact that it used to return a non-NULL
value for malloc(0).
There used to be a bug in realloc() when issued in SVC mode. The C library
maps the malloc family of calls directly to OS_Heap SWIs, but unfortunately,
the code in the C library that called OS_Heap to resize a block got the
parameters in a muddle (it got the change register's sign the wrong way
around, so blocks would shrink rather than grow, which was fatal, as you can
imagine). This was fixed a long time ago, but I can't remember nowadays
which OS it was first fixed in.
Many Acorn modules that were written in C have a function called
module_realloc() or similar to deal with this.
--
Stewart Brodie
More information about the oslib-team
mailing list