From 73b05b9d595ad5ac3949df548bf6d9aab868a4ff Mon Sep 17 00:00:00 2001 From: sergey-ryvkin <126426790+sergey-ryvkin@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:56:13 +0300 Subject: [PATCH] Update memcpy.c transfer data safety optimization --- libgcc/memcpy.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libgcc/memcpy.c b/libgcc/memcpy.c index 58b1e405627aa..4a31424dd228a 100644 --- a/libgcc/memcpy.c +++ b/libgcc/memcpy.c @@ -4,9 +4,18 @@ void * memcpy (void *dest, const void *src, size_t len) { - char *d = dest; - const char *s = src; - while (len--) - *d++ = *s++; + char *d; + const char *s; + if((size_t)destination<(size_t)source){ + s=src+len; + d=dest+len; + while(len--) + *--d = *--s; + }else if((size_t)destination>(size_t)source){ + s=src; + d=dest; + while (len--) + *d++ = *s++; + } return dest; }