Skip to content

Commit

Permalink
Fix: parse_index_access so that array index accesses in functions d…
Browse files Browse the repository at this point in the history
…on't memory crash

#175
  • Loading branch information
KennyOliver committed Jan 7, 2025
1 parent bb2c076 commit 133ac17
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parser/array_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ ASTNode *parse_index_access(ASTNode *array, ParserState *state) {
// Expect and consume `]`
expect_token(state, TOKEN_SQ_BRACKET_CLOSE,
"Expected `]` to close slice expression");
node->next = NULL;
} else if (is_array_operator(current)) {
// It's an array operator like `^+`, `+^`, `^-`, `-^`
node->type = AST_ARRAY_OPERATION;
Expand All @@ -142,6 +143,8 @@ ASTNode *parse_index_access(ASTNode *array, ParserState *state) {
parser_error("Memory allocation failed for array operator",
current);
}

node->array_operation.array = array;
node->next = NULL;
advance_token(state); // consume the operator

Expand All @@ -157,6 +160,7 @@ ASTNode *parse_index_access(ASTNode *array, ParserState *state) {
// Expect and consume `]`
expect_token(state, TOKEN_SQ_BRACKET_CLOSE,
"Expected `]` to close index expression");
node->next = NULL;
}

return node;
Expand Down

0 comments on commit 133ac17

Please sign in to comment.