[2/6,v2] newlib: memccpy: unify mask filling with other memory functions

Message ID cf55165cf59c984f55b66f0a3fe246f0bdc98784.camel@espressif.com
State New
Headers
Series None |

Commit Message

Alexey Lapshin Jan. 29, 2025, 9:07 a.m. UTC
  This change made just to have memccpy like others mem-functions
---
 newlib/libc/string/memccpy.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

-- 
2.43.0
  

Comments

Alexey Lapshin Jan. 29, 2025, 9:11 a.m. UTC | #1
Corinna, thanks for catching this issue!
  

Patch

diff --git a/newlib/libc/string/memccpy.c b/newlib/libc/string/memccpy.c
index 332332489..6e7e944fe 100644
--- a/newlib/libc/string/memccpy.c
+++ b/newlib/libc/string/memccpy.c
@@ -69,7 +69,7 @@  memccpy (void *__restrict dst0,
   if (!TOO_SMALL_LITTLE_BLOCK(len0) && !UNALIGNED_X_Y(src, dst))
     {
       unsigned int i;
-      unsigned long mask = 0;
+      unsigned long mask;
 
       aligned_dst = (long*)dst;
       aligned_src = (long*)src;
@@ -80,9 +80,10 @@  memccpy (void *__restrict dst0,
          the word-sized segment with a word-sized block of the search
          character and then detecting for the presence of NULL in the
          result.  */
-      for (i = 0; i < sizeof(mask); i++)
-        mask = (mask << 8) + endchar;
-
+      mask = endchar << 8 | endchar;
+      mask = mask << 16 | mask;
+      for (i = 32; i < sizeof(mask) * 8; i <<= 1)
+        mask = (mask << i) | mask;
 
       /* Copy one long word at a time if possible.  */
       while (!TOO_SMALL_LITTLE_BLOCK(len0))