Fixed lexing error inside token string not being on heap

This commit is contained in:
Kyler Olsen 2025-11-27 17:12:29 -07:00
parent 76a89fe03f
commit 727f461fb6
1 changed files with 8 additions and 7 deletions

View File

@ -761,14 +761,15 @@ static LexerResult parse_token_string(LexerInfo *lexer_info, char c, size_t star
}
if (current->type == SLS_ERROR) {
LexerResult e = (LexerResult){SLS_RESULT, .result = &(LexerTokenResult){
LexerTokenResult *e = (LexerTokenResult *)malloc(sizeof(LexerTokenResult));
*e = (LexerTokenResult){
.type = SLS_ERROR,
.error = (SlsError){sls_str_cpy(current->error.message), 1},
.file_info = current->file_info,
.next = NULL
}};
};
clean_token_result(head);
return e;
return (LexerResult){SLS_RESULT, .result = e};
}
if (current->result.type == TOKEN_EOF) break;
@ -921,16 +922,16 @@ static void clean_token_string(TokenString token_string) {
void clean_token_result(LexerTokenResult *head) {
// Deallocates a LexerTokenResult linked list
if (head == NULL) return;
if (head->type == SLS_ERROR) sls_str_free(&head->error.message);
else {
if (head->type == SLS_ERROR) sls_str_free(&head->error.message);
else {
if (head->result.type == TOKEN_STRING)
sls_str_free(&head->result.string_literal);
if (head->result.type == TOKEN_TOKEN_STRING)
clean_token_string(head->result.token_string);
}
}
clean_token_result(head->next);
head->next = NULL;
if (head) free(head);
if (head) free(head);
}
LexerTokenResult *get_token(LexerTokenResult *head, size_t i) {