aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/string.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/util/string.c b/util/string.c
index e896379..41855c2 100644
--- a/util/string.c
+++ b/util/string.c
@@ -4,17 +4,20 @@
void* memcpy(void* dest, const void* src, size_t len)
{
- if ((((uintptr_t)dest | (uintptr_t)src | len) & (sizeof(uintptr_t)-1)) == 0) {
- const uintptr_t* s = src;
- uintptr_t *d = dest;
- while (d < (uintptr_t*)(dest + len))
- *d++ = *s++;
- } else {
- const char* s = src;
- char *d = dest;
- while (d < (char*)(dest + len))
- *d++ = *s++;
+ const char* s = src;
+ char *d = dest;
+
+ if ((((uintptr_t)dest | (uintptr_t)src) & (sizeof(uintptr_t)-1)) == 0) {
+ while ((void*)d < (dest + len - (sizeof(uintptr_t)-1))) {
+ *(uintptr_t*)d = *(const uintptr_t*)s;
+ d += sizeof(uintptr_t);
+ s += sizeof(uintptr_t);
+ }
}
+
+ while (d < (char*)(dest + len))
+ *d++ = *s++;
+
return dest;
}