diff --git a/yml.c b/yml.c index 5369b5f..3bda708 100644 --- a/yml.c +++ b/yml.c @@ -572,11 +572,14 @@ yml_is_list(const struct yml_node *node) const struct yml_node * yml_get_value(const struct yml_node *node, const char *_path) { - char *path = strdup(_path); - - if (node->type == ROOT) + if (node != NULL && node->type == ROOT) node = node->root.root; + if (node == NULL) + return NULL; + + char *path = strdup(_path); + for (const char *part = strtok(path, "."), *next_part = strtok(NULL, "."); part != NULL; part = next_part, next_part = strtok(NULL, ".")) @@ -779,6 +782,9 @@ yml_source_column(const struct yml_node *node) static void _print_node(const struct yml_node *n, int indent) { + if (n == NULL) + return; + switch (n->type) { case ROOT: _print_node(n->root.root, indent);