aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-05-19 18:47:35 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-05-21 13:19:46 +0200
commit846f560979d14b82e348cdf83d93994dee909d70 (patch)
treeab00cfaad575a5383cf93fdfd12534cd89d9352f
parente9b426db412680de1888056c5a643b3ed8c7ded6 (diff)
downloadell-846f560979d14b82e348cdf83d93994dee909d70.tar.gz
ell-846f560979d14b82e348cdf83d93994dee909d70.tar.xz
ell-846f560979d14b82e348cdf83d93994dee909d70.zip
Mark memory allocation issues in the parser
-rwxr-xr-xell.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/ell.c b/ell.c
index 7370eea..ad52af5 100755
--- a/ell.c
+++ b/ell.c
@@ -412,8 +412,6 @@ lexer_errorf (struct lexer *self, const char *fmt, ...) {
// --- Parsing -----------------------------------------------------------------
-// FIXME: the parser generally ignores memory allocation errors
-
static void
print_string (const char *s) {
putc ('\'', stdout);
@@ -523,8 +521,10 @@ static struct item * parse_line (struct parser *self, jmp_buf out);
static struct item *
parse_prefix_list (struct item *list, const char *name) {
+ // TODO: check memory error
struct item *prefix = new_string (name, strlen (name));
prefix->next = list;
+ // TODO: check memory error
return new_list (prefix);
}
@@ -540,6 +540,7 @@ parse_item (struct parser *self, jmp_buf out) {
SKIP_NL ();
if (ACCEPT (T_STRING))
+ // TODO: check memory error, also in "self->lexer.string"
return new_string (self->lexer.string.s, self->lexer.string.len);
if (ACCEPT (T_AT)) {
result = parse_item (self, out);
@@ -551,6 +552,7 @@ parse_item (struct parser *self, jmp_buf out) {
tail = &(*tail)->next;
SKIP_NL ();
}
+ // TODO: check memory error
return new_list (result);
}
if (ACCEPT (T_LBRACKET)) {
@@ -565,6 +567,7 @@ parse_item (struct parser *self, jmp_buf out) {
while ((*tail = parse_line (self, err)))
tail = &(*tail)->next;
EXPECT (T_RBRACE);
+ // TODO: check memory error
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) {
- if (ACCEPT (T_NEWLINE)) {
- if (result)
- return new_list (result);
- } else {
+ if (!ACCEPT (T_NEWLINE)) {
*tail = parse_item (self, err);
tail = &(*tail)->next;
+ } else if (result) {
+ // TODO: check memory error
+ return new_list (result);
}
}
if (result)
+ // TODO: check memory error
return new_list (result);
return NULL;
}