Usermode/libc - Minor fix to memmove
authorJohn Hodge <[email protected]>
Tue, 10 Sep 2013 00:34:29 +0000 (08:34 +0800)
committerJohn Hodge <[email protected]>
Tue, 10 Sep 2013 00:34:29 +0000 (08:34 +0800)
Usermode/Libraries/libc.so_src/heap.c
Usermode/Libraries/libc.so_src/string.c

index 3cbd0b5..9b6799b 100644 (file)
@@ -177,7 +177,7 @@ EXPORT void *calloc(size_t __nmemb, size_t __size)
 EXPORT void free(void *mem)\r
 {\r
        heap_head       *head = (void*)((intptr_t)mem-sizeof(heap_head));\r
-       \r
+\r
        // Sanity please!\r
        if(!mem)        return;\r
        \r
index 2ab271f..6ee6d6c 100644 (file)
@@ -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;
 }
 

UCC git Repository :: git.ucc.asn.au