From fb2f240c6ffb1d10c0dd0d482322b7f08308e63e Mon Sep 17 00:00:00 2001 From: JozanLeClerc <bousset.rudy@gmail.com> Date: Tue, 1 Sep 2020 16:25:07 +0200 Subject: Secured malloc --- src/s_line.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/s_line.c') diff --git a/src/s_line.c b/src/s_line.c index b47b453..ae0ec07 100644 --- a/src/s_line.c +++ b/src/s_line.c @@ -80,7 +80,7 @@ t_line link->next = NULL; return (link); } - link->com = s_com_new(word, msh); - /* TODO: check link->com = NULL */ + if ((link->com = s_com_new(word, msh)) == NULL) + return (NULL); return (link); } -- cgit v1.2.3 From d742075e1af0c063ef9677f157263c0d45253f73 Mon Sep 17 00:00:00 2001 From: JozanLeClerc <bousset.rudy@gmail.com> Date: Tue, 8 Sep 2020 19:32:40 +0200 Subject: Rework in progress --- src/s_line.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'src/s_line.c') diff --git a/src/s_line.c b/src/s_line.c index ae0ec07..b198fff 100644 --- a/src/s_line.c +++ b/src/s_line.c @@ -14,26 +14,30 @@ #include <stdlib.h> #include <stdint.h> +#include "d_define.h" #include "p_line.h" #include "s_com.h" #include "s_struct.h" -t_line - *s_line_last(t_line *line) +t_line_block + *s_line_last(t_line_block *line) { while (line->next != NULL) + { line = line->next; + } return (line); } void - s_line_add_back(t_line **aline, - t_line *new) + s_line_add_back(t_line_block **aline, t_line_block *new) { - t_line *tmp; + t_line_block *tmp; - if (!*aline) + if (*aline == NULL) + { *aline = new; + } else { tmp = s_line_last(*aline); @@ -42,45 +46,43 @@ void } void - s_line_clear(t_line **line) + s_line_clear(t_line_block **line) { - t_line *tmp; - t_line *renext; + t_line_block *tmp; + t_line_block *renext; - if (!line) + if (line == NULL) + { return ; + } tmp = *line; while (tmp != NULL) { renext = tmp->next; - if (tmp->com != NULL) - { - s_com_destroy(&tmp->com); - } ft_memdel((void*)&tmp); tmp = renext; } *line = NULL; } -t_line - *s_line_new(const char word[], - t_msh *msh) +t_line_block + *s_line_new(const char word[], uint8_t nextif) { - t_line *link; + t_line_block *link; - if ((link = (t_line*)malloc(sizeof(t_line))) == NULL) + if ((link = (t_line_block*)malloc(sizeof(t_line_block))) == NULL) return (NULL); - link->nextif = 0; - link->com = NULL; - link->pipes = NULL; + link->lblock[0] = C_NUL; + link->nextif = nextif; link->next = NULL; if (word == NULL) { link->next = NULL; return (link); } - if ((link->com = s_com_new(word, msh)) == NULL) - return (NULL); + else + { + ft_strlcpy(link->lblock, word, 4096); + } return (link); } -- cgit v1.2.3 From 44cd349d69a11fec6c698ec45a59e373cad56c2e Mon Sep 17 00:00:00 2001 From: JozanLeClerc <bousset.rudy@gmail.com> Date: Wed, 9 Sep 2020 18:40:11 +0200 Subject: qwe --- src/s_line.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/s_line.c') diff --git a/src/s_line.c b/src/s_line.c index b198fff..c6e2e0b 100644 --- a/src/s_line.c +++ b/src/s_line.c @@ -59,6 +59,7 @@ void while (tmp != NULL) { renext = tmp->next; + ft_memdel((void*)&tmp->lblock); ft_memdel((void*)&tmp); tmp = renext; } @@ -72,7 +73,7 @@ t_line_block if ((link = (t_line_block*)malloc(sizeof(t_line_block))) == NULL) return (NULL); - link->lblock[0] = C_NUL; + link->lblock = NULL; link->nextif = nextif; link->next = NULL; if (word == NULL) @@ -80,9 +81,9 @@ t_line_block link->next = NULL; return (link); } - else + else if ((link->lblock = ft_strdup(word)) == NULL) { - ft_strlcpy(link->lblock, word, 4096); + return (NULL); } return (link); } -- cgit v1.2.3