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);
             ^~~~~~~~~~~~~~~
This commit is contained in:
Phil Turnbull 2017-06-14 10:58:34 -04:00
parent da099d0bbe
commit d1b19e8196

View file

@ -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);