summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-10-18 17:33:38 +0200
committerJo-Philipp Wich <jo@mein.io>2020-10-18 17:33:38 +0200
commit279d0b5d27f406bb60cb7e9ea2222a3c83eb7980 (patch)
tree9c93ac215f809aba571277563634763a691730e8 /lib.c
parent6bbc6137d2bc0ec79e740ea50e6edee0496bcf85 (diff)
lib: properly handle parse errors at EOF
At EOF, ut_parse_error() will receive 0 as token offset, which led to a null pointer dereference when creating the exception value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 2dba05b..bbc60a6 100644
--- a/lib.c
+++ b/lib.c
@@ -199,7 +199,9 @@ ut_parse_error(struct ut_state *s, uint32_t off, uint64_t *tokens, int max_token
}
}
- rv = ut_new_exception(s, op->off, "Syntax error: Unexpected token\n%s", msg);
+ rv = ut_new_exception(s,
+ op ? op->off : s->lex.lastoff,
+ "Syntax error: Unexpected token\n%s", msg);
free(msg);
return rv;