check the value of nodeptr in tnode_t::source_range.

Avoids a possible nullptr dereference
This commit is contained in:
Lior Stern 2020-03-31 17:03:13 +03:00 committed by ridiculousfish
parent d6e2110cdf
commit 1b23e5471d

View File

@ -97,7 +97,7 @@ class tnode_t {
uint8_t child_count() const { return nodeptr ? nodeptr->child_count : 0; }
maybe_t<source_range_t> source_range() const {
if (nodeptr->source_start == NODE_OFFSET_INVALID) return none();
if (!nodeptr || nodeptr->source_start == NODE_OFFSET_INVALID) return none();
return source_range_t{nodeptr->source_start, nodeptr->source_length};
}