From 5ace4d77c714e52aa141a0f174819c199a3d31e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 29 Apr 2019 18:49:44 +0200 Subject: [PATCH] yml: handle root's node being NULL --- yml.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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);