From: Rich Felker Date: Sun, 23 Sep 2018 04:03:08 +0000 (-0400) Subject: fix undefined pointer comparison in memmove X-Git-Tag: v1.1.21~73 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=debadaa238e90fce897b467a9efefcbbc0155d06;p=musl fix undefined pointer comparison in memmove the comparison must take place in the address space model as an integer type, since comparing pointers that are not pointing into the same array is undefined. the subsequent d=n, algebraically !(-n=s-d-n. --- diff --git a/src/string/memmove.c b/src/string/memmove.c index 27f670e1..f225bb30 100644 --- a/src/string/memmove.c +++ b/src/string/memmove.c @@ -10,7 +10,7 @@ void *memmove(void *dest, const void *src, size_t n) const char *s = src; if (d==s) return d; - if (s+n <= d || d+n <= s) return memcpy(d, s, n); + if ((uintptr_t)s-(uintptr_t)d-n <= -2*n) return memcpy(d, s, n); if (d