yml: handle root's node being NULL

This commit is contained in:
Daniel Eklöf 2019-04-29 18:49:44 +02:00
parent 6622616ec7
commit 5ace4d77c7

12
yml.c
View file

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