From: John Hodge Date: Tue, 10 Sep 2013 00:34:29 +0000 (+0800) Subject: Usermode/libc - Minor fix to memmove X-Git-Tag: rel0.15~232 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c7946415abcd9c7a86ecde867d44cb50a249c349;p=tpg%2Facess2.git Usermode/libc - Minor fix to memmove --- diff --git a/Usermode/Libraries/libc.so_src/heap.c b/Usermode/Libraries/libc.so_src/heap.c index 3cbd0b53..9b6799b0 100644 --- a/Usermode/Libraries/libc.so_src/heap.c +++ b/Usermode/Libraries/libc.so_src/heap.c @@ -177,7 +177,7 @@ EXPORT void *calloc(size_t __nmemb, size_t __size) EXPORT void free(void *mem) { heap_head *head = (void*)((intptr_t)mem-sizeof(heap_head)); - + // Sanity please! if(!mem) return; diff --git a/Usermode/Libraries/libc.so_src/string.c b/Usermode/Libraries/libc.so_src/string.c index 2ab271f5..6ee6d6ca 100644 --- a/Usermode/Libraries/libc.so_src/string.c +++ b/Usermode/Libraries/libc.so_src/string.c @@ -282,14 +282,23 @@ EXPORT void *memcpy(void *__dest, const void *__src, size_t count) */ EXPORT void *memmove(void *dest, const void *src, size_t count) { - char *sp = (char *)src; + const char *sp = (const char *)src; char *dp = (char *)dest; // Check if the areas overlap - if( (uintptr_t)src < (uintptr_t)dest && (uintptr_t)dest < (uintptr_t)src+count ) - for(;count--;) - dp[count] = sp[count]; - else + if( sp >= dp+count ) + memcpy(dest, src, count); + else if( dp >= sp+count ) memcpy(dest, src, count); + else { + if( sp < dp ) { + while(count--) + dp[count] = sp[count]; + } + else { + while(count--) + *dp++ = *sp++; + } + } return dest; }