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 20:18:14 +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> <Pine dot LNX dot 4 dot 64 dot 1308181949000 dot 10353 at digraph dot polyomino dot org dot uk> <20130818201026 dot GA9545 at domone>
On Sun, 18 Aug 2013, Ondrej Bilka wrote:
> 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?
This question does not engage with my comment. I'm talking simple cases
such as dest == src + 1 and n == 2 (where (size_t)-3 >= 4).
--
Joseph S. Myers
joseph@codesourcery.com