aboutsummaryrefslogtreecommitdiffstats
path: root/libc/string
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string')
-rw-r--r--libc/string/memmove.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index 072104b6c..7c1e9b2fd 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -32,10 +32,10 @@ void *memmove(void *dst, const void *src, size_t n)
{
const char *p = src;
char *q = dst;
- /* We can use the optimized memcpy if the destination is below the
- * source (i.e. q < p), or if it is completely over it (i.e. q >= p+n).
+ /* We can use the optimized memcpy if the destination is completely below the
+ * source (i.e. q+n <= p), or if it is completely over it (i.e. q >= p+n).
*/
- if (__builtin_expect((q < p) || ((size_t)(q - p) >= n), 1)) {
+ if (__builtin_expect((q + n < p) || (q >= p + n), 1)) {
return memcpy(dst, src, n);
} else {
bcopy(src, dst, n);