forked from external/yambar
yml: handle root's node being NULL
This commit is contained in:
parent
6622616ec7
commit
5ace4d77c7
1 changed files with 9 additions and 3 deletions
12
yml.c
12
yml.c
|
@ -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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue