diff options
author | Tom Rini <trini@konsulko.com> | 2021-01-18 07:55:54 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-01-18 07:55:54 -0500 |
commit | 19c5fdffdc41bfd606b455b46e834d1bff4b2c1e (patch) | |
tree | db1c5abebf12e9aaef80d8e22a472357027b5287 /lib/string.c | |
parent | 14ea1b3635b4af8d9e283e3671f7ee872d50b859 (diff) | |
parent | ad80a8d0877922db95fd0410314504c840d9d850 (diff) |
Merge branch '2021-01-16-assorted-improvements'
- Assorted testing improvements and fixes
- Assorted code cleanups
Diffstat (limited to 'lib/string.c')
-rw-r--r-- | lib/string.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/string.c b/lib/string.c index ae7835f600..73b984123d 100644 --- a/lib/string.c +++ b/lib/string.c @@ -567,7 +567,19 @@ void * memmove(void * dest,const void *src,size_t count) { char *tmp, *s; - if (dest <= src) { + if (dest <= src || (src + count) <= dest) { + /* + * Use the fast memcpy implementation (ARCH optimized or lib/string.c) when it is possible: + * - when dest is before src (assuming that memcpy is doing forward-copying) + * - when destination don't overlap the source buffer (src + count <= dest) + * + * WARNING: the first optimisation cause an issue, when __HAVE_ARCH_MEMCPY is defined, + * __HAVE_ARCH_MEMMOVE is not defined and if the memcpy ARCH-specific + * implementation is not doing a forward-copying. + * + * No issue today because memcpy is doing a forward-copying in lib/string.c and for ARM32 + * architecture; no other arches use __HAVE_ARCH_MEMCPY without __HAVE_ARCH_MEMMOVE. + */ memcpy(dest, src, count); } else { tmp = (char *) dest + count; |