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: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: <libc-alpha at sourceware dot org>
- Date: Sun, 18 Aug 2013 19:55:46 +0000
- Subject: Re: [RFC] Do not call memmove when memcpy suffices.
- References: <20130813111123 dot GA1623 at domone dot kolej dot mff dot cuni dot cz>
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, 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