From f6af23622c44b51cdcbd404e01a69c3341d5e9e4 Mon Sep 17 00:00:00 2001 From: Takuma Tsubo Date: Tue, 29 Apr 2025 16:17:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?node=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E5=85=85=E5=AE=9F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/initialize.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/initialize.c b/src/initialize.c index 569a8e4..2bed7c5 100644 --- a/src/initialize.c +++ b/src/initialize.c @@ -6,13 +6,13 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 15:42:46 by dayano #+# #+# */ -/* Updated: 2025/04/20 18:39:53 by ttsubo ### ########.fr */ +/* Updated: 2025/04/29 16:17:19 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ #include "main.h" -static void _split_key_value(char *env_val, char **key_out, char **val_out) +static int _split_key_value(char *env_val, char **key_out, char **val_out) { size_t env_len; size_t eq_pos; @@ -22,9 +22,31 @@ static void _split_key_value(char *env_val, char **key_out, char **val_out) *key_out = NULL; *val_out = NULL; if (eq_pos == ft_strlen(env_val)) - return ; + return (1); *key_out = ft_substr(env_val, 0, eq_pos); *val_out = ft_substr(env_val, eq_pos + 1, env_len - eq_pos - 1); + if (!*key_out || !*val_out) + return (1); + return (0); +} + +static void _free_node(t_env *node) +{ + free(node->key); + free(node->value); + free(node); +} + +static void _free_nodes(t_env **head) +{ + t_env *tmp; + + while (*head) + { + tmp = (*head)->next; + _free_node(*head); + *head = tmp; + } } static t_env *create_envp_list(char **envp) @@ -42,9 +64,8 @@ static t_env *create_envp_list(char **envp) node = ft_calloc(1, sizeof(t_env)); if (!node) return (NULL); - _split_key_value(envp[i], &(node->key), &(node->value)); - if (!node->key || !node->value) - return (free(node), NULL); + if (!_split_key_value(envp[i], &(node->key), &(node->value))) + return (_free_nodes(&head), _free_node(node), NULL); node->next = NULL; if (!head) head = node; From f27a26ec00bb3a305133ae5d525b43f296f62bfb Mon Sep 17 00:00:00 2001 From: Takuma Tsubo Date: Tue, 29 Apr 2025 16:20:29 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=BC=8F=E3=83=9F?= =?UTF-8?q?=E3=82=B9=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/initialize.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/initialize.c b/src/initialize.c index 2bed7c5..21264d4 100644 --- a/src/initialize.c +++ b/src/initialize.c @@ -6,7 +6,7 @@ /* By: ttsubo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 15:42:46 by dayano #+# #+# */ -/* Updated: 2025/04/29 16:17:19 by ttsubo ### ########.fr */ +/* Updated: 2025/04/29 16:18:49 by ttsubo ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,7 @@ static t_env *create_envp_list(char **envp) node = ft_calloc(1, sizeof(t_env)); if (!node) return (NULL); - if (!_split_key_value(envp[i], &(node->key), &(node->value))) + if (_split_key_value(envp[i], &(node->key), &(node->value))) return (_free_nodes(&head), _free_node(node), NULL); node->next = NULL; if (!head)