You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2019/07/16 09:56:42 UTC

[mynewt-core] branch master updated: libc/baselibc: Fix memset on ARM

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

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ecbc8d  libc/baselibc: Fix memset on ARM
3ecbc8d is described below

commit 3ecbc8da276886da4af38e55c023b4e7b624c514
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Jul 15 22:56:41 2019 +0200

    libc/baselibc: Fix memset on ARM
    
    If buffer is unaligned and fits in single word, the number of unaligned
    bytes at the end of buffer is calculated as a negative number. This
    causes memset to overwrite few bytes before actual buffer.
    
    To fix this we just need to check if calculated value is negative and
    use the other routine to fill unaligned bytes.
---
 libc/baselibc/src/memset.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libc/baselibc/src/memset.c b/libc/baselibc/src/memset.c
index e67f1a5..7a72804 100644
--- a/libc/baselibc/src/memset.c
+++ b/libc/baselibc/src/memset.c
@@ -44,6 +44,7 @@ void *memset(void *dst, int c, size_t n)
                   "   movs r4, #3                           \n"
                   "   ands r3, r3, r4                       \n"
                   "   subs r3, %[len], r3                   \n"
+                  "   bmi  3f                               \n"
                   "   b    2f                               \n"
                   /* fill non-word aligned bytes at the end of buffer */
                   "1: subs %[len], #1                       \n"
@@ -57,9 +58,9 @@ void *memset(void *dst, int c, size_t n)
                   "   bpl  1b                               \n"
                   "   adds %[len], #4                       \n"
                   /* fill remaining non-word aligned bytes */
-                  "   b    2f                               \n"
+                  "   b    3f                               \n"
                   "1: strb %[val], [%[buf], %[len]]         \n"
-                  "2: subs %[len], #1                       \n"
+                  "3: subs %[len], #1                       \n"
                   "   bpl  1b                               \n"
                   : [buf] "+r" (q), [val] "+r" (c), [len] "+r" (n)
                   :