|
|
Message-ID: <20250330121748.699050-4-cgoettsche@seltendoof.de>
Date: Sun, 30 Mar 2025 14:17:38 +0200
From: Christian Göttsche <cgoettsche@...tendoof.de>
To: musl@...ts.openwall.com
Cc: Christian Göttsche <cgzones@...glemail.com>
Subject: [PATCH 4/4] memcpy: avoid dropping const qualifier
From: Christian Göttsche <cgzones@...glemail.com>
For const correctness retain the const qualifier for pointer casts of
the source parameter.
---
src/string/memcpy.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/src/string/memcpy.c b/src/string/memcpy.c
index 06e88742..51d9669e 100644
--- a/src/string/memcpy.c
+++ b/src/string/memcpy.c
@@ -24,18 +24,18 @@ void *memcpy(void *restrict dest, const void *restrict src, size_t n)
if ((uintptr_t)d % 4 == 0) {
for (; n>=16; s+=16, d+=16, n-=16) {
- *(u32 *)(d+0) = *(u32 *)(s+0);
- *(u32 *)(d+4) = *(u32 *)(s+4);
- *(u32 *)(d+8) = *(u32 *)(s+8);
- *(u32 *)(d+12) = *(u32 *)(s+12);
+ *(u32 *)(d+0) = *(const u32 *)(s+0);
+ *(u32 *)(d+4) = *(const u32 *)(s+4);
+ *(u32 *)(d+8) = *(const u32 *)(s+8);
+ *(u32 *)(d+12) = *(const u32 *)(s+12);
}
if (n&8) {
- *(u32 *)(d+0) = *(u32 *)(s+0);
- *(u32 *)(d+4) = *(u32 *)(s+4);
+ *(u32 *)(d+0) = *(const u32 *)(s+0);
+ *(u32 *)(d+4) = *(const u32 *)(s+4);
d += 8; s += 8;
}
if (n&4) {
- *(u32 *)(d+0) = *(u32 *)(s+0);
+ *(u32 *)(d+0) = *(const u32 *)(s+0);
d += 4; s += 4;
}
if (n&2) {
@@ -49,50 +49,50 @@ void *memcpy(void *restrict dest, const void *restrict src, size_t n)
if (n >= 32) switch ((uintptr_t)d % 4) {
case 1:
- w = *(u32 *)s;
+ w = *(const u32 *)s;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
n -= 3;
for (; n>=17; s+=16, d+=16, n-=16) {
- x = *(u32 *)(s+1);
+ x = *(const u32 *)(s+1);
*(u32 *)(d+0) = (w LS 24) | (x RS 8);
- w = *(u32 *)(s+5);
+ w = *(const u32 *)(s+5);
*(u32 *)(d+4) = (x LS 24) | (w RS 8);
- x = *(u32 *)(s+9);
+ x = *(const u32 *)(s+9);
*(u32 *)(d+8) = (w LS 24) | (x RS 8);
- w = *(u32 *)(s+13);
+ w = *(const u32 *)(s+13);
*(u32 *)(d+12) = (x LS 24) | (w RS 8);
}
break;
case 2:
- w = *(u32 *)s;
+ w = *(const u32 *)s;
*d++ = *s++;
*d++ = *s++;
n -= 2;
for (; n>=18; s+=16, d+=16, n-=16) {
- x = *(u32 *)(s+2);
+ x = *(const u32 *)(s+2);
*(u32 *)(d+0) = (w LS 16) | (x RS 16);
- w = *(u32 *)(s+6);
+ w = *(const u32 *)(s+6);
*(u32 *)(d+4) = (x LS 16) | (w RS 16);
- x = *(u32 *)(s+10);
+ x = *(const u32 *)(s+10);
*(u32 *)(d+8) = (w LS 16) | (x RS 16);
- w = *(u32 *)(s+14);
+ w = *(const u32 *)(s+14);
*(u32 *)(d+12) = (x LS 16) | (w RS 16);
}
break;
case 3:
- w = *(u32 *)s;
+ w = *(const u32 *)s;
*d++ = *s++;
n -= 1;
for (; n>=19; s+=16, d+=16, n-=16) {
- x = *(u32 *)(s+3);
+ x = *(const u32 *)(s+3);
*(u32 *)(d+0) = (w LS 8) | (x RS 24);
- w = *(u32 *)(s+7);
+ w = *(const u32 *)(s+7);
*(u32 *)(d+4) = (x LS 8) | (w RS 24);
- x = *(u32 *)(s+11);
+ x = *(const u32 *)(s+11);
*(u32 *)(d+8) = (w LS 8) | (x RS 24);
- w = *(u32 *)(s+15);
+ w = *(const u32 *)(s+15);
*(u32 *)(d+12) = (x LS 8) | (w RS 24);
}
break;
--
2.49.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.