diff options
Diffstat (limited to 'ft_strdup.s')
| -rw-r--r-- | ft_strdup.s | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ft_strdup.s b/ft_strdup.s index 8ff46b5..a31f36f 100644 --- a/ft_strdup.s +++ b/ft_strdup.s @@ -21,14 +21,19 @@ _ft_strdup: push rdi ; save rdi because it will be overwrite for malloc call _ft_strlen ; rdi is still == str - inc rax ; len++ for '\0' + inc rax ; len++ for '\0' - mov rdi, rax ; size to malloc + mov rdi, rax ; size to malloc call _malloc + cmp rax, 0 + je FT_STRDUP_ERROR - pop rsi ; original str as src - mov rdi, rax ; allocated as dest + pop rsi ; original str as src + mov rdi, rax ; allocated as dest call _ft_strcpy ret +FT_STRDUP_ERROR: + pop rdi + ret |
