This commit is contained in:
2024-03-27 23:02:24 +01:00
parent f9396fc10e
commit b7a3b7140b
4 changed files with 25 additions and 16 deletions

View File

@@ -5,18 +5,18 @@ extern ft_strcpy
extern malloc
ft_strdup:
call ft_strlen
inc rax
push rdi
call ft_strlen
inc rax ; we add one to the result of strlen for the \0
push rdi ; we put rdi in r10 for later use
mov rdi, rax ; move the result of strlen in rdi
call malloc wrt ..plt
test rax, rax
call malloc wrt ..plt ;
test rax, rax ; test if malloc failled
je .end
pop rsi
pop rsi ; we take the value we saved earlier
mov rdi, rax ; move the result of malloc into rdi (override strlen result)
call ft_strcpy
ret
.end:
pop r8
pop rsi
ret