From 28c275b0ea38a341e6ce158d631bb41109863dd2 Mon Sep 17 00:00:00 2001 From: Camel Coder Date: Mon, 15 Jul 2024 05:44:36 +0200 Subject: [PATCH] fix memcpy&memset alignment (#37) --- libs/klib/src/string.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/klib/src/string.c b/libs/klib/src/string.c index 5c870a07..35f13c83 100644 --- a/libs/klib/src/string.c +++ b/libs/klib/src/string.c @@ -53,7 +53,7 @@ void* memset(void* v,int c,size_t n){ if (n >= threshold) { // first let dst aligned by 8 bytes - int pad = (uintptr_t)dst % 8; + int pad = (8 - (uintptr_t)dst % 8) % 8; n -= pad; while (pad --) { *dst ++ = c; } @@ -102,7 +102,7 @@ void* memcpy(void* out, const void* in, size_t n) { if (n >= threshold && is_align8) { // first let dst aligned by 8 bytes - int pad = (uintptr_t)dst % 8; + int pad = (8 - (uintptr_t)dst % 8) % 8; n -= pad; while (pad --) { *dst ++ = *src ++; } @@ -131,7 +131,7 @@ void* memcpy(void* out, const void* in, size_t n) { if (n >= threshold && is_align4) { // first let dst aligned by 4 bytes - int pad = (uintptr_t)dst % 4; + int pad = (4 - (uintptr_t)dst % 4) % 4; n -= pad; while (pad --) { *dst ++ = *src ++; }