diff --git a/42sh/Makefile b/42sh/Makefile index f6fd3377..c565f7df 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/21 00:39:34 by ariard ### ########.fr # +# Updated: 2017/03/21 10:36:25 by gwojda ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -fvisibility=hidden #-fsanitize=address +FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 9d78c82b..60a1ec4f 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/20 12:32:15 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:02:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,6 +55,8 @@ # define TOUCHE_F5 892427035 # define TOUCHE_F6 925981467 +# define SIZE_LINE 512 + # define CORRUPT 1 # define ERROR_CNTL_R 1 diff --git a/42sh/src/completion/c_match_glob.c b/42sh/src/completion/c_match_glob.c index 6970b95c..b06fa160 100644 --- a/42sh/src/completion/c_match_glob.c +++ b/42sh/src/completion/c_match_glob.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */ -/* Updated: 2017/03/18 12:23:18 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:09:42 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,10 +34,16 @@ static void c_replace_globbing(char **glob, size_t start) ref_mid = ft_sstrtostr(glob, " "); ref_next = ft_strdup(str + pos); data_singleton()->line.input = ft_str3join(ref_prev, ref_mid, ref_next); - free(ref_prev); - free(ref_mid); - free(ref_next); - free(str); + if (ft_strlen(data_singleton()->line.input) > SIZE_LINE) + { + ft_strdel(&data_singleton()->line.input); + data_singleton()->line.input = str; + } + else + ft_strdel(&str); + ft_strdel(&ref_prev); + ft_strdel(&ref_mid); + ft_strdel(&ref_next); ft_sstrfree(glob); } diff --git a/42sh/src/line_editing/copy_cut_paste.c b/42sh/src/line_editing/copy_cut_paste.c index 8e7e330a..98e24bd4 100644 --- a/42sh/src/line_editing/copy_cut_paste.c +++ b/42sh/src/line_editing/copy_cut_paste.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/17 11:56:42 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:32:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,8 +49,12 @@ int ft_v(char **str, size_t *pos) if (!*str || !tmp) return (0); while (tmp[++i]) + { + if (ft_strlen(*str) > SIZE_LINE) + break ; if (!(*str = ft_realloc_imput(*str, tmp[i], *pos + i))) return (-1); + } if (*pos) { --(*pos); @@ -75,7 +79,7 @@ int ft_x(char **str, size_t *pos) ft_strdel(tmp); if (!(*tmp = ft_strdupi_space(&(*str)[*pos]))) return (-1); - i = ft_strlen(*tmp); + i = ft_strlen(*tmp) - 1; while (i >= 0) { if (!(*str = ft_remove_imput(*str, *pos + i))) diff --git a/42sh/src/line_editing/get_key.c b/42sh/src/line_editing/get_key.c index 5bfec31b..da810243 100644 --- a/42sh/src/line_editing/get_key.c +++ b/42sh/src/line_editing/get_key.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ -/* Updated: 2017/03/18 11:19:01 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:34:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line_editing/init_history.c b/42sh/src/line_editing/init_history.c index 4c8f5c57..38dc438b 100644 --- a/42sh/src/line_editing/init_history.c +++ b/42sh/src/line_editing/init_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */ -/* Updated: 2017/03/17 16:01:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:39:24 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ static int ft_str_is_print(char *str) static void corrupt_history(int corrupt, char *home) { if (corrupt) - ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history\n", home); + ft_dprintf(2, "42sh: corrupt history file %s/.42sh_history\n", home); } void ft_init_history(void) diff --git a/42sh/src/line_editing/lib_line_editing/toolz_parseur.c b/42sh/src/line_editing/lib_line_editing/toolz_parseur.c index d0f82a11..d74258ee 100644 --- a/42sh/src/line_editing/lib_line_editing/toolz_parseur.c +++ b/42sh/src/line_editing/lib_line_editing/toolz_parseur.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ -/* Updated: 2017/03/16 16:39:24 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:03:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,8 @@ char *ft_realloc_imput(char *str, int a, size_t pos) tmp[0] = (char)a; tmp[1] = '\0'; + if (ft_strlen(str) > SIZE_LINE) + return (str); if (!str) { new_str = ft_strdup(tmp); diff --git a/42sh/src/line_editing/print_and_del.c b/42sh/src/line_editing/print_and_del.c index 0999701b..ed0751f1 100644 --- a/42sh/src/line_editing/print_and_del.c +++ b/42sh/src/line_editing/print_and_del.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */ -/* Updated: 2017/03/17 12:32:51 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:14:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,8 @@ int ft_print(int ret, char **str, size_t *pos) int j; j = 0; + if (ft_strlen(*str) > SIZE_LINE) + return (0); if (!(*str = ft_realloc_imput(*str, ret, *pos))) return (-1); while (*(*str + *pos + j) && *(*str + *pos + j) != '\n') diff --git a/42sh/src/line_editing/queue.c b/42sh/src/line_editing/queue.c index f0567514..300b63ef 100644 --- a/42sh/src/line_editing/queue.c +++ b/42sh/src/line_editing/queue.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:47:31 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 10:15:13 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,8 @@ static int ft_read_it_3(char **str, char t[5], size_t *pos, int *j) { if (t[i] && ft_isprint(t[i])) { + if (ft_strlen(*str) > SIZE_LINE) + return (0); if (!(*str = ft_realloc_imput(*str, t[i], *pos))) return (-1); ++(*pos);