Fix wrong pointer depth and gotos offset
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 10 Jul 2024 18:41:35 +0000 (20:41 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 18:21:22 +0000 (20:21 +0200)
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

index 42d463ca371ba9046b5a92422ee0e9a654afc06d..3a275f061292b847b90afa746189b436c9be39ed 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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;