From d1b19e81964df7a19c630787448ac2dc8f710012 Mon Sep 17 00:00:00 2001 From: Phil Turnbull Date: Wed, 14 Jun 2017 10:58:34 -0400 Subject: [PATCH] Prevent NULL pointer dereference in parser__accept parser__select_tree can return true if 'left != NULL' and 'right == NULL' which will later cause a NULL ptr deref: src/runtime/parser.c:842:14: warning: Access to field 'ref_count' results in a dereference of a null pointer (loaded from variable 'root') assert(root->ref_count > 0); ^~~~~~~~~~~~~~~ --- src/runtime/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/parser.c b/src/runtime/parser.c index a7198778..b54b8250 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -839,7 +839,7 @@ static void parser__accept(Parser *self, StackVersion version, if (parser__select_tree(self, self->finished_tree, root)) { ts_tree_release(self->finished_tree); - assert(root->ref_count > 0); + assert((root == NULL) || (root->ref_count > 0)); self->finished_tree = root; } else { ts_tree_release(root);