Skip to content

Commit 790bee8

Browse files
authored
Merge pull request #351 from LeaYeh/build-sanitizer
2 parents 0d2fb9d + 0626bdb commit 790bee8

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

Makefile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# By: ldulling <ldulling@student.42.fr> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: 2023/12/23 03:22:46 by ldulling #+# #+# #
9-
# Updated: 2024/04/02 23:08:11 by ldulling ### ########.fr #
9+
# Updated: 2024/07/02 17:06:11 by ldulling ### ########.fr #
1010
# #
1111
# **************************************************************************** #
1212

@@ -41,9 +41,13 @@ BUILDFILES := Makefile \
4141

4242
# Flags
4343

44-
CC := cc
44+
CC ?= cc
4545
CC_VERSION := $(shell $(CC) --version | head -1)
46-
CFLAGS := -Wall -Wextra -Werror -ggdb3
46+
CFLAGS_STD := -Wall -Wextra -Werror
47+
CFLAGS_DBG := -ggdb3
48+
CFLAGS_SAN := -fsanitize=address,undefined,bounds,float-divide-by-zero
49+
CFLAGS_OPT := -O3
50+
CFLAGS ?= $(CFLAGS_STD) $(CFLAGS_DBG)
4751
INCFLAGS := $(addprefix -I,$(INC_DIR) $(LIB_INCLUDES))
4852
LIBFLAGS := $(addprefix -L,$(LIBRARIES)) \
4953
$(addprefix -l,$(patsubst lib%,%,$(notdir \
@@ -119,8 +123,8 @@ DEP_SUBDIRS := $(sort $(dir $(DEP)))
119123

120124
# ***************************** BUILD PROCESS ******************************** #
121125

122-
.PHONY : all test run val noenv valfd build lib waitforlib clean \
123-
fclean ffclean re
126+
.PHONY : all fast run san val noenv valfd build lib waitforlib \
127+
clean fclean ffclean re
124128

125129

126130
# Compilation
@@ -140,9 +144,18 @@ all :
140144
fi; \
141145
fi
142146

147+
fast : CFLAGS := $(CFLAGS_STD) $(CFLAGS_OPT)
148+
fast : re
149+
$(MAKE) clean
150+
143151
run : all
144152
"./$(NAME)"
145153

154+
san : CFLAGS := $(CFLAGS_STD) $(CFLAGS_DBG) $(CFLAGS_SAN)
155+
san : re
156+
$(MAKE) clean
157+
"./$(NAME)"
158+
146159
val : all
147160
$(VALGRIND) $(VALGRINDFLAGS) "./$(NAME)"
148161

libraries/libft/src/put/ft_putchar_fd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void ft_putchar_fd(char c, int fd)
1616
{
1717
if (fd < 0)
1818
return ;
19-
(void) write(fd, &c, 1);
19+
if (write(fd, &c, 1) == -1)
20+
return ;
2021
return ;
2122
}

libraries/libft/src/put/ft_putendl_fd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void ft_putendl_fd(char *s, int fd)
1616
{
1717
if (s == NULL || fd < 0)
1818
return ;
19-
(void) write(fd, s, ft_strlen(s));
20-
(void) write(fd, "\n", 1);
19+
if (write(fd, s, ft_strlen(s)) == -1 || write(fd, "\n", 1) == -1)
20+
return ;
2121
return ;
2222
}

libraries/libft/src/put/ft_putnbr_fd.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ void ft_putnbr_fd(int n, int fd)
1919
if (fd < 0)
2020
return ;
2121
if (n == INT_MIN)
22-
(void) write(fd, "-2147483648", 11);
22+
{
23+
if (write(fd, "-2147483648", 11) == -1)
24+
return ;
25+
}
2326
else if (n < 0)
2427
{
25-
(void) write(fd, "-", 1);
28+
if (write(fd, "-", 1) == -1)
29+
return ;
2630
putnbr_fd_recursive(-n, fd);
2731
}
2832
else
@@ -35,6 +39,7 @@ static void putnbr_fd_recursive(int n, int fd)
3539
if (n >= 10)
3640
putnbr_fd_recursive(n / 10, fd);
3741
n = n % 10 + '0';
38-
(void) write(fd, &n, 1);
42+
if (write(fd, &n, 1) == -1)
43+
return ;
3944
return ;
4045
}

libraries/libft/src/put/ft_putstr_fd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void ft_putstr_fd(char *s, int fd)
1616
{
1717
if (s == NULL || fd < 0)
1818
return ;
19-
(void) write(fd, s, ft_strlen(s));
19+
if (write(fd, s, ft_strlen(s)) == -1)
20+
return ;
2021
return ;
2122
}

libraries/libft/src/strings/ft_strjoin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ char *ft_strjoin(char const *s1, char const *s2)
2626
if (strj == NULL)
2727
return (NULL);
2828
if (len1)
29-
(void) ft_memcpy(&strj[0], s1, len1);
29+
ft_memcpy(&strj[0], s1, len1);
3030
if (len2)
31-
(void) ft_memcpy(&strj[len1], s2, len2);
31+
ft_memcpy(&strj[len1], s2, len2);
3232
strj[len1 + len2] = '\0';
3333
return (strj);
3434
}

0 commit comments

Comments
 (0)