This is an automated email from the ASF dual-hosted git repository.

jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 7f5f0f5e53dda97c29779d8c51075330e91ed3fa
Author: anjiahao <[email protected]>
AuthorDate: Thu Sep 25 09:30:05 2025 +0800

    libs/libc/string: Fix asrc alignment for unaligned access in memrchr.
    
    memrchr scans backward, so the original implementation aligned
    (x + 1) rather than x:
    
      #define UNALIGNED(x) ((long)(uintptr_t)((x) + 1) & (sizeof(long) - 1))
    
    while the common UNALIGNED_X() macro checks the pointer itself.  Pass
    src0 + 1 to UNALIGNED_X() to restore the original behavior, otherwise
    asrc is off by one byte and the word loop reads the wrong data.
    
    Assisted-by: Claude:claude-opus-5
    Signed-off-by: anjiahao <[email protected]>
---
 libs/libc/string/lib_bsdmemrchr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libs/libc/string/lib_bsdmemrchr.c 
b/libs/libc/string/lib_bsdmemrchr.c
index 3e213a05315..b16651dfcf0 100644
--- a/libs/libc/string/lib_bsdmemrchr.c
+++ b/libs/libc/string/lib_bsdmemrchr.c
@@ -63,7 +63,7 @@ FAR void *memrchr(FAR const void *s, int c, size_t n)
   libc_data_t mask;
   unsigned int i;
 
-  while (UNALIGNED_X(src0))
+  while (UNALIGNED_X(src0 + 1))
     {
       if (!n--)
         {

Reply via email to