Fix peg bug when there is no default grammar set.

This could result in a segfault when we attempt to
read from a NULL pointer.
This commit is contained in:
Calvin Rose 2021-05-20 21:57:22 -05:00
parent 81186bf262
commit 2db7945d6f
1 changed files with 3 additions and 1 deletions

View File

@ -1148,7 +1148,9 @@ static uint32_t peg_compile1(Builder *b, Janet peg) {
for (; i > 0 && janet_checktype(peg, JANET_KEYWORD); --i) {
Janet nextPeg = janet_table_get_ex(grammar, peg, &grammar);
if (!grammar || janet_checktype(nextPeg, JANET_NIL)) {
nextPeg = janet_table_get(b->default_grammar, peg);
nextPeg = (b->default_grammar == NULL)
? janet_wrap_nil()
: janet_table_get(b->default_grammar, peg);
if (janet_checktype(nextPeg, JANET_NIL)) {
peg_panic(b, "unknown rule");
}