Fix issues in mandatory

This commit is contained in:
Xamora 2026-09-20 03:10:41 +02:00
parent 4ef28d1ce9
commit 510ab19fd2
3 changed files with 4 additions and 15 deletions

6
main.c
View file

@ -183,12 +183,13 @@ test_calloc() {
printf("error: %p\n", error); printf("error: %p\n", error);
char *empty = ft_calloc(0, 0); char *empty = ft_calloc(0, 0);
printf("empty: %s_%p\n", empty, empty); printf("empty: %p\n", empty);
char *buf = ft_calloc(10, 1); char *buf = ft_calloc(10, 1);
strcpy(buf, "test"); strcpy(buf, "test");
printf("test: %s_%p\n", buf, buf); printf("test: %s_%p\n", buf, buf);
free(error);
free(empty); free(empty);
free(buf); free(buf);
} }
@ -203,12 +204,13 @@ test_calloc() {
printf("error: %p\n", error); printf("error: %p\n", error);
char *empty = calloc(0, 0); char *empty = calloc(0, 0);
printf("empty: %s_%p\n", empty, empty); printf("empty: %p\n", empty);
char *buf = calloc(10, 1); char *buf = calloc(10, 1);
strcpy(buf, "test"); strcpy(buf, "test");
printf("test: %s_%p\n", buf, buf); printf("test: %s_%p\n", buf, buf);
free(error);
free(empty); free(empty);
free(buf); free(buf);
} }

View file

@ -9,22 +9,13 @@ section .text
push rbx push rbx
mov rbx, rdi mov rbx, rdi
mul rbx, rsi
cmp rbx, rdi
jl return_null
mov rdi, rbx mov rdi, rbx
call malloc wrt ..plt call malloc wrt ..plt
mov rdi, rax mov rdi, rax
inc rbx
mov rsi, rbx mov rsi, rbx
call bzero wrt ..plt call bzero wrt ..plt
pop rbx pop rbx
ret ret
return_null:
pop rbx
mov rax, 0
ret

View file

@ -6,8 +6,6 @@ section .text
global ft_strcpy global ft_strcpy
; rdi = dst, rsi = src ; rdi = dst, rsi = src
ft_strcpy: ft_strcpy:
; push rbp
mov rax, 0 ; counter mov rax, 0 ; counter
mov rcx, 0 mov rcx, 0
mov rdx, 0 mov rdx, 0
@ -21,7 +19,5 @@ section .text
cmp dl, 0 cmp dl, 0
jne loop jne loop
; pop rbp
mov rax, rdi mov rax, rdi
ret ret