Skip to content

Commit adea850

Browse files
Abdallahs70keith-packard
authored andcommitted
rv_strcpy: move checking the 4th byte in case of 32-bit to 64-bit
This check is not needed in case of `_riscv_xlen=32` at all as it's checking the last byte which is supposed to be `NULL` (by standard `strcpy` input is null terminated string) Also it causes function to set 0 to out of boundary address in case of `_riscv_xlen=32` Reducing assembly instructions of `strcpy` in case of `_riscv_xlen=32` Signed-off-by: Abdallah Abdelhafeez <[email protected]>
1 parent 4d35a31 commit adea850

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

newlib/libc/machine/riscv/rv_strcpy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ char *__libc_strcpy(char *dst, const char *src, bool ret_start)
9797
if (!(*dst++ = src[0])) return dst0;
9898
if (!(*dst++ = src[1])) return dst0;
9999
if (!(*dst++ = src[2])) return dst0;
100-
if (!(*dst++ = src[3])) return dst0;
101100
#if __riscv_xlen == 64
101+
if (!(*dst++ = src[3])) return dst0;
102102
if (!(*dst++ = src[4])) return dst0;
103103
if (!(*dst++ = src[5])) return dst0;
104104
if (!(*dst++ = src[6])) return dst0;
@@ -109,8 +109,8 @@ char *__libc_strcpy(char *dst, const char *src, bool ret_start)
109109
if (!(*dst++ = src[0])) return dst - 1;
110110
if (!(*dst++ = src[1])) return dst - 1;
111111
if (!(*dst++ = src[2])) return dst - 1;
112-
if (!(*dst++ = src[3])) return dst - 1;
113112
#if __riscv_xlen == 64
113+
if (!(*dst++ = src[3])) return dst - 1;
114114
if (!(*dst++ = src[4])) return dst - 1;
115115
if (!(*dst++ = src[5])) return dst - 1;
116116
if (!(*dst++ = src[6])) return dst - 1;

0 commit comments

Comments
 (0)