about summary refs log tree commit diff
path: root/src/string/memmove.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-09-06 20:25:48 -0400
committerRich Felker <dalias@aerifal.cx>2012-09-06 20:25:48 -0400
commit594318fd3d13c7dda1ea87a76934e052ac74301f (patch)
tree71a11d048014f76a434eedcec17929a1f8a223f7 /src/string/memmove.c
parentfcfba99503746e44585d7e318562dd425e8ff390 (diff)
downloadmusl-594318fd3d13c7dda1ea87a76934e052ac74301f.tar.gz
musl-594318fd3d13c7dda1ea87a76934e052ac74301f.tar.xz
musl-594318fd3d13c7dda1ea87a76934e052ac74301f.zip
remove dependency of memmove on memcpy direction
this commit introduces a performance regression in many uses of
memmove, which will need to be addressed before the next release. i'm
making it as a temporary measure so that the restrict patch can be
committed without invoking undefined behavior when memmove calls
memcpy with overlapping regions.
Diffstat (limited to 'src/string/memmove.c')
-rw-r--r--src/string/memmove.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/string/memmove.c b/src/string/memmove.c
index 22bb4b35..9153a644 100644
--- a/src/string/memmove.c
+++ b/src/string/memmove.c
@@ -5,10 +5,9 @@ void *memmove(void *dest, const void *src, size_t n)
 	char *d = dest;
 	const char *s = src;
 	if (d==s) return d;
-	if ((size_t)(d-s) < n) {
+	if ((size_t)(d-s) < n)
 		while (n--) d[n] = s[n];
-		return dest;
-	}
-	/* Assumes memcpy is overlap-safe when dest < src */
-	return memcpy(d, s, n);
+	else
+		while (n--) *d++ = *s++;
+	return dest;
 }