This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: BUG: in mallocr.c: overlapping realloc fails


> > - 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]