Browse Source

[enh] Don't print NULL string with ft_putstr() and it's three derivatives. It prevent segfault.

Moul 4 years ago
parent
commit
6a08dcc32b
4 changed files with 12 additions and 8 deletions
  1. 3 1
      src/ft_putendl.c
  2. 3 1
      src/ft_putendl_fd.c
  3. 3 2
      src/ft_putstr.c
  4. 3 4
      src/ft_putstr_fd.c

+ 3 - 1
src/ft_putendl.c

@@ -6,7 +6,7 @@
 /*   By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2014/11/06 17:21:20 by mazimi            #+#    #+#             */
-/*   Updated: 2015/09/30 19:17:11 by mazimi           ###   ########.fr       */
+/*   Updated: 2016/02/22 18:50:37 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,6 +14,8 @@
 
 void	ft_putendl(char const *s)
 {
+	if (s == NULL)
+		return ;
 	write(1, s, ft_strlen(s));
 	ft_putchar('\n');
 }

+ 3 - 1
src/ft_putendl_fd.c

@@ -6,7 +6,7 @@
 /*   By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2014/11/06 17:21:20 by mazimi            #+#    #+#             */
-/*   Updated: 2015/09/30 18:06:53 by mazimi           ###   ########.fr       */
+/*   Updated: 2016/02/22 18:51:00 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,6 +14,8 @@
 
 void	ft_putendl_fd(char const *s, int fd)
 {
+	if (s == NULL)
+		return ;
 	write(fd, s, ft_strlen(s));
 	write(fd, "\n", 1);
 }

+ 3 - 2
src/ft_putstr.c

@@ -6,7 +6,7 @@
 /*   By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2014/11/04 15:15:03 by mazimi            #+#    #+#             */
-/*   Updated: 2015/09/29 14:09:02 by mazimi           ###   ########.fr       */
+/*   Updated: 2016/02/22 18:51:27 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,5 +14,6 @@
 
 void	ft_putstr(char const *s)
 {
-	write(1, s, ft_strlen(s));
+	if (s != NULL)
+		write(1, s, ft_strlen(s));
 }

+ 3 - 4
src/ft_putstr_fd.c

@@ -6,7 +6,7 @@
 /*   By: mazimi <mazimi@student.42.fr>              +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2014/11/06 18:15:07 by mazimi            #+#    #+#             */
-/*   Updated: 2015/09/29 14:08:48 by mazimi           ###   ########.fr       */
+/*   Updated: 2016/02/22 18:51:45 by mazimi           ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,7 +14,6 @@
 
 void	ft_putstr_fd(char const *s, int fd)
 {
-	if (s == NULL)
-		return ;
-	write(fd, s, ft_strlen(s));
+	if (s != NULL)
+		write(fd, s, ft_strlen(s));
 }