diff --git a/src/Makefile b/src/Makefile index fb32e95..1bf1701 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,18 +11,23 @@ # **************************************************************************** # NAME = libft.a + SOURCES = ft_atoi.c ft_bzero.c ft_calloc.c ft_isalnum.c ft_isalpha.c \ - ft_isascii.c ft_isdigit.c ft_isprint.c ft_itoa.c ft_lstadd_back.c\ - ft_lstadd_front.c ft_lstclear.c ft_lstdelone.c ft_lstiter.c \ - ft_lstlast.c ft_lstmap.c ft_lstnew.c ft_lstsize.c ft_memchr.c \ + ft_isascii.c ft_isdigit.c ft_isprint.c ft_itoa.c ft_memchr.c \ ft_memcmp.c ft_memcpy.c ft_memmove.c ft_memset.c ft_putchar_fd.c \ ft_putendl_fd.c ft_putnbr_fd.c ft_putstr_fd.c ft_split.c ft_strchr.c \ ft_strdup.c ft_striteri.c ft_strjoin.c ft_strlcat.c ft_strlcpy.c \ ft_strlen.c ft_strmapi.c ft_strncmp.c ft_strnstr.c ft_strrchr.c \ ft_strtrim.c ft_substr.c ft_tolower.c ft_toupper.c +BONUS_SOURCES = ft_lstadd_back.c ft_lstadd_front.c ft_lstclear.c \ + ft_lstdelone.c ft_lstiter.c ft_lstlast.c ft_lstmap.c \ + ft_lstnew.c ft_lstsize.c + OBJECTS = $(SOURCES:.c=.o) +BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o) + CC = gcc CFLAGS = -Wall -Wextra -Werror @@ -31,11 +36,14 @@ all: $(NAME) $(NAME): $(OBJECTS) $(AR) -r $@ $? +bonus: $(OBJECTS) $(BONUS_OBJECTS) + $(AR) -r $(NAME) $? + %.o: %.c $(CC) -c $(CFLAGS) $? clean: - rm -f $(OBJECTS) $(BOBJECTS) + rm -f $(OBJECTS) $(BONUS_OBJECTS) fclean: clean rm -f $(NAME) diff --git a/src/ft_atoi.c b/src/ft_atoi.c index 9c73997..46ea8bf 100644 --- a/src/ft_atoi.c +++ b/src/ft_atoi.c @@ -28,7 +28,7 @@ int ft_atoi(const char *nptr) nptr++; res = 0; sign = 1; - while (*nptr == '-' || *nptr == '+') + if (*nptr == '-' || *nptr == '+') { if (*nptr == '-') sign *= -1; diff --git a/src/ft_calloc.c b/src/ft_calloc.c index 38bf0a2..caa2917 100644 --- a/src/ft_calloc.c +++ b/src/ft_calloc.c @@ -17,6 +17,10 @@ void *ft_calloc(size_t nmemb, size_t size) { void *ptr; + if (nmemb && nmemb > (size_t) -1 / nmemb) + { + return (0); + } ptr = malloc(nmemb * size); if (ptr) ft_bzero(ptr, nmemb * size); diff --git a/src/ft_strnstr.c b/src/ft_strnstr.c index 676783e..324599c 100644 --- a/src/ft_strnstr.c +++ b/src/ft_strnstr.c @@ -18,7 +18,7 @@ char *ft_strnstr(const char *big, const char *little, size_t len) size_t j; i = 0; - if (*little == '\0' || len == 0) + if (*little == '\0') return ((char *) big); while (big[i] && i < len) {