strcat: Better logic for determining max amount of characters to copy

This commit is contained in:
2025-07-06 19:13:05 +02:00
parent ddd44d5a68
commit a47ab3cdc6

View File

@@ -60,30 +60,25 @@ strcpy:
; rsi* (arg) Pointer to src[]
; rdx (arg) Size of dest[]
; rcx* Counter for movsb
; r8* Backup for rdi
; r8* Backup for rdi (point to start of dest)
; r9* Backup for rsi
; r10* Current length of dest[]
; r10* Backup for rdi (point to end of dest)
strcat:
mov r8, rdi
mov r9, rsi
call strlen
sub rdx, rax
dec rdi
mov r10, rdi
mov rdi, rsi
call strlen
mov rcx, rax
mov rdi, r8
call strlen
mov r10, rax
mov rdi, r8
add rcx, rax
cmp rcx, rdx
cmova rcx, rdx
cmp rcx, rdx
cmp rax, rdx
jb .copy
dec rcx
.copy:
mov rdi, r8
dec rdx
.copy:
mov rcx, rdx
mov rsi, r9
add rdi, r10
sub rcx, r10
mov rdi, r10
cld
rep movsb
mov byte [rdi], EOS