From d242a498377350add06ba70da2f7ce1d2c593cc1 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 31 Jan 2024 21:00:08 -0500 Subject: implement both directions directly rather than punting to memcpy() --- src/string/memmove.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/string/memmove.c b/src/string/memmove.c index 22677b6d..5d6dd3e0 100644 --- a/src/string/memmove.c +++ b/src/string/memmove.c @@ -10,16 +10,17 @@ void * memmove(void *s1, const void *s2, size_t n) ASSERT_NONNULL(s2); if (s1 < s2) { - return memcpy(s1, s2, n); - } - - /* reverse memcpy() */ - while (n > 0) { + for (size_t i = 0; i < n; i++) { + ((char*)s1)[i] = ((char*)s2)[i]; + } + } else { + while (n > 0) { + ((char*)s1)[n] = ((char*)s2)[n]; + n--; + } + /* last byte */ ((char*)s1)[n] = ((char*)s2)[n]; - n--; } - /* last byte */ - ((char*)s1)[n] = ((char*)s2)[n]; /* RETURN_ALWAYS(ARGUMENT(s1)); -- cgit v1.2.1