From 8788c5857f7f46eb96350afd3f701bc1082356dd Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Tue, 6 Sep 2016 21:05:16 +0200 Subject: Check for NULL --- ezxml.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ezxml.c b/ezxml.c index b02400f..b267b40 100644 --- a/ezxml.c +++ b/ezxml.c @@ -16,11 +16,15 @@ int process(char *fn) { ezxml_t body = ezxml_get(ezdoc, "body", -1); if (!body) { - fprintf(stderr, "No body-tag found in file '%s'\n", fn); + fprintf(stderr, "No body-tag found in file '%s'. Exiting.\n", fn); + return 1; } + for (ezxml_t c = ezxml_child(body, "sec"); c; c = c->next) { ezxml_t t = ezxml_get(c, "title", -1); - printf("section-title: %s\n", t->txt); + if (t) { + printf("section-title: %s\n", t->txt); + } } printf("\n"); -- cgit v1.2.3