Mark memory allocation issues in the parser
This commit is contained in:
parent
e9b426db41
commit
846f560979
16
ell.c
16
ell.c
|
@ -412,8 +412,6 @@ lexer_errorf (struct lexer *self, const char *fmt, ...) {
|
||||||
|
|
||||||
// --- Parsing -----------------------------------------------------------------
|
// --- Parsing -----------------------------------------------------------------
|
||||||
|
|
||||||
// FIXME: the parser generally ignores memory allocation errors
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_string (const char *s) {
|
print_string (const char *s) {
|
||||||
putc ('\'', stdout);
|
putc ('\'', stdout);
|
||||||
|
@ -523,8 +521,10 @@ static struct item * parse_line (struct parser *self, jmp_buf out);
|
||||||
|
|
||||||
static struct item *
|
static struct item *
|
||||||
parse_prefix_list (struct item *list, const char *name) {
|
parse_prefix_list (struct item *list, const char *name) {
|
||||||
|
// TODO: check memory error
|
||||||
struct item *prefix = new_string (name, strlen (name));
|
struct item *prefix = new_string (name, strlen (name));
|
||||||
prefix->next = list;
|
prefix->next = list;
|
||||||
|
// TODO: check memory error
|
||||||
return new_list (prefix);
|
return new_list (prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,6 +540,7 @@ parse_item (struct parser *self, jmp_buf out) {
|
||||||
|
|
||||||
SKIP_NL ();
|
SKIP_NL ();
|
||||||
if (ACCEPT (T_STRING))
|
if (ACCEPT (T_STRING))
|
||||||
|
// TODO: check memory error, also in "self->lexer.string"
|
||||||
return new_string (self->lexer.string.s, self->lexer.string.len);
|
return new_string (self->lexer.string.s, self->lexer.string.len);
|
||||||
if (ACCEPT (T_AT)) {
|
if (ACCEPT (T_AT)) {
|
||||||
result = parse_item (self, out);
|
result = parse_item (self, out);
|
||||||
|
@ -551,6 +552,7 @@ parse_item (struct parser *self, jmp_buf out) {
|
||||||
tail = &(*tail)->next;
|
tail = &(*tail)->next;
|
||||||
SKIP_NL ();
|
SKIP_NL ();
|
||||||
}
|
}
|
||||||
|
// TODO: check memory error
|
||||||
return new_list (result);
|
return new_list (result);
|
||||||
}
|
}
|
||||||
if (ACCEPT (T_LBRACKET)) {
|
if (ACCEPT (T_LBRACKET)) {
|
||||||
|
@ -565,6 +567,7 @@ parse_item (struct parser *self, jmp_buf out) {
|
||||||
while ((*tail = parse_line (self, err)))
|
while ((*tail = parse_line (self, err)))
|
||||||
tail = &(*tail)->next;
|
tail = &(*tail)->next;
|
||||||
EXPECT (T_RBRACE);
|
EXPECT (T_RBRACE);
|
||||||
|
// TODO: check memory error
|
||||||
return parse_prefix_list (new_list (result), "quote");
|
return parse_prefix_list (new_list (result), "quote");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,15 +588,16 @@ parse_line (struct parser *self, jmp_buf out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (PEEK () != T_RBRACE && PEEK () != T_ABORT) {
|
while (PEEK () != T_RBRACE && PEEK () != T_ABORT) {
|
||||||
if (ACCEPT (T_NEWLINE)) {
|
if (!ACCEPT (T_NEWLINE)) {
|
||||||
if (result)
|
|
||||||
return new_list (result);
|
|
||||||
} else {
|
|
||||||
*tail = parse_item (self, err);
|
*tail = parse_item (self, err);
|
||||||
tail = &(*tail)->next;
|
tail = &(*tail)->next;
|
||||||
|
} else if (result) {
|
||||||
|
// TODO: check memory error
|
||||||
|
return new_list (result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
|
// TODO: check memory error
|
||||||
return new_list (result);
|
return new_list (result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue