From 7b6978c9e2cbf475d567f8e6af82350258e9d07c Mon Sep 17 00:00:00 2001 From: Xamora Date: Sun, 20 Sep 2026 16:11:56 +0200 Subject: [PATCH] fix issue with null send to asm function --- main.c | 8 ++++++++ src/ft_strcpy.s | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/main.c b/main.c index 82b9208..bd2e0c3 100644 --- a/main.c +++ b/main.c @@ -77,12 +77,20 @@ test_strcpy() { { printf("ft_strcpy:\n"); + ft_strcpy(NULL, NULL); + char src_empty[] = ""; char dst_empty[] = ""; char *ret = ft_strcpy(dst_empty, src_empty); printf ("ret: %s_%p, src: %s_%p, dest: %s_%p\n", ret, ret, src_empty, src_empty, dst_empty, dst_empty); + char null_char[0]; + ft_strcpy(null_char, NULL); + + ft_strcpy(dst_empty, NULL); + ft_strcpy(NULL, src_empty); + char src[10] = "src"; char dst[10] = "dst"; printf ("src: %s, dest: %s\n", src, dst); diff --git a/src/ft_strcpy.s b/src/ft_strcpy.s index ae99d85..1303f10 100644 --- a/src/ft_strcpy.s +++ b/src/ft_strcpy.s @@ -9,6 +9,11 @@ section .text mov rax, 0 ; counter mov rdx, 0 + cmp rdi, 0 + je endloop + cmp rsi, 0 + je endloop + loop: mov dl, [rsi + rax] ; get char from src mov [rdi + rax], dl ; replace char by char @@ -17,6 +22,7 @@ section .text cmp dl, 0 jne loop + endloop: mov rax, rdi ret