From d34df1ec329ea7b826a8a17639560631675b312a Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Wed, 10 Jul 2024 20:41:35 +0200 Subject: [PATCH] Fix wrong pointer depth and gotos offset The translation function accessed t_generator_state * instead of the correct t_generator_state**. The gotos vector in the table rows is indexed from 0 but uses the tokens after the eof_token hence the index needs to be offset. --- ft_parse/ft_parsing_table_generate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ft_parse/ft_parsing_table_generate.c b/ft_parse/ft_parsing_table_generate.c index 42d463c..3a275f0 100644 --- a/ft_parse/ft_parsing_table_generate.c +++ b/ft_parse/ft_parsing_table_generate.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 11:16:53 by ljiriste #+# #+# */ -/* Updated: 2024/07/10 00:27:24 by ljiriste ### ########.fr */ +/* Updated: 2024/07/10 20:25:44 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -739,7 +739,7 @@ void convert_gotos(t_vec *gotos, const t_generator_state *state, const t_vec *to { token = ft_vec_caccess(&state->goto_tokens, i); if (!(is_terminal_token(token, tokens) || !ft_strcmp(token->type, eof_token.type))) - *(ssize_t *)ft_vec_access(gotos, get_token_position(token, tokens)) = *(const ssize_t *)ft_vec_caccess(&state->goto_states, i); + *(ssize_t *)ft_vec_access(gotos, get_token_position(token, tokens) - get_token_position(&eof_token, tokens) - 1) = *(const ssize_t *)ft_vec_caccess(&state->goto_states, i); ++i; } return ; @@ -820,13 +820,13 @@ t_ft_stat translate_to_table(t_parsing_table *table, const t_vec *states) { size_t i; t_ft_stat res; - const t_generator_state *state; + t_generator_state *const *state; i = 0; while (i < states->size) { state = ft_vec_caccess(states, i); - res = add_table_row(table, state); + res = add_table_row(table, *state); if (res != success) return (res); ++i; -- 2.30.2