This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [RFC] Do not call memmove when memcpy suffices.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Sun, 18 Aug 2013 22:10:26 +0200
- Subject: Re: [RFC] Do not call memmove when memcpy suffices.
- References: <20130813111123 dot GA1623 at domone dot kolej dot mff dot cuni dot cz> <Pine dot LNX dot 4 dot 64 dot 1308181949000 dot 10353 at digraph dot polyomino dot org dot uk>
On Sun, Aug 18, 2013 at 07:55:46PM +0000, Joseph S. Myers wrote:
> On Tue, 13 Aug 2013, Ondrej Bilka wrote:
>
> > #define memmove(_dest, _src, _n) \
> > ({ \
> > char *dest = (_dest); \
> > char *src = (_src); \
> > size_t n = (_n); \
> > if (__glibc_likely ((size_t)((src - n) - dest) >= 2 * n)) \
> > return memcpy (dest, src, n); \
> > else \
> > return memmove (dest, src, n); \
> > })
>
> I don't see why this is safe. Say the arguments overlap with src < dest,
> ((src - n) - dest) negative and becoming large and positive when cast to
> size_t,
And did you compute conditions how small dest must be for wraparound to
occur?
> so the test passes and memcpy is called - but the glibc ABI
> guarantee for memcpy requires that there is no overlap in either direction
> (except maybe in the case where src == dest). Do you mean ((src + n) -
> dest)?
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
--
Sand fleas eating the Internet cables