From 95e346c2eec3f00bc16ba8c92e7d56ca7cd3d7da Mon Sep 17 00:00:00 2001 From: lalgarra Date: Sun, 5 Oct 2025 14:16:10 +0200 Subject: [PATCH] ft_memmove() --- Makefile | 8 +++-- ft_memmove_expected.output | 2 ++ ft_memmove_test.c | 62 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 ft_memmove_expected.output create mode 100644 ft_memmove_test.c diff --git a/Makefile b/Makefile index d129aa5..61edd20 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: lalgarra +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/10/03 18:03:12 by lalgarra #+# #+# # -# Updated: 2025/10/05 13:30:04 by lalgarra ### ########.fr # +# Updated: 2025/10/05 14:09:02 by lalgarra ### ########.fr # # # # **************************************************************************** # @@ -14,11 +14,13 @@ LIBDIR = ../repo_libft_algarra #LIBDIR = ../vogsphere_repo -CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR) +CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR) \ + -fsanitize=address -Wanalyzer-malloc-leak TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \ ft_isprint_test ft_toupper_test ft_tolower_test ft_strlen_test \ - ft_memset_test ft_bzero_test ft_memcpy_test ft_calloc_test + ft_memset_test ft_bzero_test ft_memcpy_test ft_calloc_test \ + ft_memmove_test %_test : %_test.c $(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test diff --git a/ft_memmove_expected.output b/ft_memmove_expected.output new file mode 100644 index 0000000..cceb3ae --- /dev/null +++ b/ft_memmove_expected.output @@ -0,0 +1,2 @@ +test 1: +Lorem ipsum dolor si; Lorem iLorem ipsu si diff --git a/ft_memmove_test.c b/ft_memmove_test.c new file mode 100644 index 0000000..46b2d23 --- /dev/null +++ b/ft_memmove_test.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove_test.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lalgarra +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/10/05 13:21:43 by lalgarra #+# #+# */ +/* Updated: 2025/10/05 14:02:12 by lalgarra ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +/* +static void do_test3(char *prefix) +{ + int *buff; + size_t buflen; + size_t size; + + buflen = 5; + size = 0; + buff = ft_calloc(buflen, size); + printf("%ssize= %lu; buff == NULL: %i\n", prefix, size, buff == NULL); + free(buff); +} + +static void do_test2(char *prefix) +{ + int *buff; + size_t buflen; + + buflen = 0; + buff = ft_calloc(buflen, sizeof(int)); + printf("%sbuflen = %lu; buff == NULL: %i\n", prefix, buflen, buff == NULL); + free(buff); +} +*/ +static void do_test1(char *prefix) +{ + char buf[128]; + int fd; + + fd = STDOUT_FILENO; + ft_bzero(buf, 128); + ft_memcpy(buf, "Lorem ipsum dolor sit amet consectetur adipiscing elit.", 20); + ft_putstr_fd(prefix, fd); + ft_putchar_fd('\n', fd); + ft_putstr_fd(buf, fd); + ft_putstr_fd("; ", fd); + ft_memmove(buf + 7, buf, 10); + ft_putendl_fd(buf, fd); +} + +int main(void) +{ + do_test1("test 1: "); + return (0); +}