From 17f50d3f3446e7c08bb3d948914dbaed960f101f Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Sat, 15 Jun 2024 14:34:03 +0200 Subject: [PATCH] Fix some bugs These bugs include: infinite loop not freeing alocated memory not initializing a struct before it may be returned --- ft_parse/ft_parse.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ft_parse/ft_parse.c b/ft_parse/ft_parse.c index 259a826..ca4180c 100644 --- a/ft_parse/ft_parse.c +++ b/ft_parse/ft_parse.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/20 20:51:36 by ljiriste #+# #+# */ -/* Updated: 2024/06/15 10:06:32 by ljiriste ### ########.fr */ +/* Updated: 2024/06/15 14:32:50 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -132,7 +132,7 @@ static size_t get_lookahead_size(t_vec *tokens) while (i < tokens->size) { token = (t_token *)ft_vec_access(tokens, i); - if (ft_strcmp(token->type, "$")) + if (!ft_strcmp(token->type, "$")) return (i + 1); ++i; } @@ -202,10 +202,13 @@ static t_vec parse_header(const char *header) if (!token.type || ft_vec_append(&tokens, &token) != success) { free(token.type); + free(condensed_line); ft_vec_free(&tokens, free_token); return (tokens); } + ++i; } + free(condensed_line); return (tokens); } @@ -222,10 +225,7 @@ t_parsing_table ft_load_parsing_table(const char *filename, if (load_rules(&table.rules, rules_filename)) return (table); fd = open(filename, O_RDONLY); - if (fd < 0 || - ft_vec_init(&table.rules, sizeof(t_grammar_rule)) || - ft_vec_init(&table.states, sizeof(t_parser_state)) || - load_rules(&table.rules, rules_filename)) + if (fd < 0) return (table); line = get_next_line(fd); table.tokens = parse_header(line); -- 2.30.2