BUG: in mallocr.c: overlapping realloc fails

Fery engard.ferenc@innomed.hu
Mon Jun 6 09:56:00 GMT 2005


> > - the platform's memcpy() copies with decreasing addresses (e.g. SH2
> > platforms).
> >
> 
> This last point is the source of the problem.  Normal memcpy implementations go
> forward and thus, overlapping only occurs if the destination is after the
> source, but before it's end.  This can't occur in a realloc so no check was
> necessary.

Well, there is not such term as 'normal' implementation. :-(

> I believe the simple answer is to use memmove () instead of memcpy ().  The
> memmove () implementation should be smart enough to check for overlapping and if
> not, use the regular memcpy logic.

This is the simple answer, but maybe it is not the perfect solution, as
I suppose using memmove() everywhere where malloc currently uses
memcpy() is a performance degrade. This is the only place where
overlapping
can occur, so maybe you should use memmove() only here.

Regards:
Ferenc



More information about the Newlib mailing list