summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kaiser2024-03-26 10:50:48 +0100
committerDominik Kaiser2024-03-26 10:50:48 +0100
commitcef09ac068d69cb2621ade938c6164aa6b1815c7 (patch)
tree1cb23cff95e5e9d1e6893938aa38e34fe35a1459
parent1a0bce1446dda5bd8338d18bc842566905fac30b (diff)
downloadget_next_line-cef09ac068d69cb2621ade938c6164aa6b1815c7.tar.gz
get_next_line-cef09ac068d69cb2621ade938c6164aa6b1815c7.zip
Add null checkHEADmaster
-rw-r--r--get_next_line.c5
-rw-r--r--get_next_line_utils.c7
2 files changed, 8 insertions, 4 deletions
diff --git a/get_next_line.c b/get_next_line.c
index e34210d..46edb73 100644
--- a/get_next_line.c
+++ b/get_next_line.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 14:13:51 by dkaiser #+# #+# */
-/* Updated: 2024/03/25 14:21:58 by dkaiser ### ########.fr */
+/* Updated: 2024/03/25 15:26:21 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -52,9 +52,8 @@ static void get_next_line_rec(int fd, char *buf, char **result, int pos)
clear_buffer(buf, 0);
free(*result);
*result = NULL;
- return ;
}
- if (readlen > 0)
+ else if (readlen > 0)
get_next_line_rec(fd, buf, result, 0);
}
}
diff --git a/get_next_line_utils.c b/get_next_line_utils.c
index 3f25bba..61171be 100644
--- a/get_next_line_utils.c
+++ b/get_next_line_utils.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/15 14:14:59 by dkaiser #+# #+# */
-/* Updated: 2024/03/25 14:18:50 by dkaiser ### ########.fr */
+/* Updated: 2024/03/26 10:49:08 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,6 +16,8 @@ int ft_strlen(const char *str)
{
int len;
+ if (!str)
+ return (0);
len = 0;
while (str[len])
len++;
@@ -40,7 +42,10 @@ char *str_add_buffer(char *old_str, char *buf, int buf_len)
len = ft_strlen(old_str) + buf_len;
result = malloc(sizeof(char) * (len + 1));
if (!result)
+ {
+ free(old_str);
return (NULL);
+ }
result[len] = '\0';
i = 0;
while (old_str && old_str[i])