Fixed lexing error inside token string not being on heap
This commit is contained in:
parent
76a89fe03f
commit
727f461fb6
|
|
@ -761,14 +761,15 @@ static LexerResult parse_token_string(LexerInfo *lexer_info, char c, size_t star
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current->type == SLS_ERROR) {
|
if (current->type == SLS_ERROR) {
|
||||||
LexerResult e = (LexerResult){SLS_RESULT, .result = &(LexerTokenResult){
|
LexerTokenResult *e = (LexerTokenResult *)malloc(sizeof(LexerTokenResult));
|
||||||
|
*e = (LexerTokenResult){
|
||||||
.type = SLS_ERROR,
|
.type = SLS_ERROR,
|
||||||
.error = (SlsError){sls_str_cpy(current->error.message), 1},
|
.error = (SlsError){sls_str_cpy(current->error.message), 1},
|
||||||
.file_info = current->file_info,
|
.file_info = current->file_info,
|
||||||
.next = NULL
|
.next = NULL
|
||||||
}};
|
};
|
||||||
clean_token_result(head);
|
clean_token_result(head);
|
||||||
return e;
|
return (LexerResult){SLS_RESULT, .result = e};
|
||||||
}
|
}
|
||||||
if (current->result.type == TOKEN_EOF) break;
|
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) {
|
void clean_token_result(LexerTokenResult *head) {
|
||||||
// Deallocates a LexerTokenResult linked list
|
// Deallocates a LexerTokenResult linked list
|
||||||
if (head == NULL) return;
|
if (head == NULL) return;
|
||||||
if (head->type == SLS_ERROR) sls_str_free(&head->error.message);
|
if (head->type == SLS_ERROR) sls_str_free(&head->error.message);
|
||||||
else {
|
else {
|
||||||
if (head->result.type == TOKEN_STRING)
|
if (head->result.type == TOKEN_STRING)
|
||||||
sls_str_free(&head->result.string_literal);
|
sls_str_free(&head->result.string_literal);
|
||||||
if (head->result.type == TOKEN_TOKEN_STRING)
|
if (head->result.type == TOKEN_TOKEN_STRING)
|
||||||
clean_token_string(head->result.token_string);
|
clean_token_string(head->result.token_string);
|
||||||
}
|
}
|
||||||
clean_token_result(head->next);
|
clean_token_result(head->next);
|
||||||
head->next = NULL;
|
head->next = NULL;
|
||||||
if (head) free(head);
|
if (head) free(head);
|
||||||
}
|
}
|
||||||
|
|
||||||
LexerTokenResult *get_token(LexerTokenResult *head, size_t i) {
|
LexerTokenResult *get_token(LexerTokenResult *head, size_t i) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue