This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: [RFC] Do not call memmove when memcpy suffices.


On Sun, Aug 18, 2013 at 08:18:14PM +0000, Joseph S. Myers wrote:
> 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).
>
Ah, I got substraction opposite, it should be dest - (src - n)
 
> -- 
> Joseph S. Myers
> joseph@codesourcery.com


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