From: Michael Göhler Date: Thu, 25 Dec 2014 05:24:05 +0000 (+0100) Subject: fixed header-only SEGV, closes #66 X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=8a77ead5006867bb2572d80072645178fc74dbe4;p=smdp.git fixed header-only SEGV, closes #66 --- diff --git a/src/markdown.c b/src/markdown.c index 22ebdbf..05c77be 100644 --- a/src/markdown.c +++ b/src/markdown.c @@ -66,7 +66,8 @@ void free_line(line_t *line) { line_t *next; while (line) { next = line->next; - (line->text->delete)(line->text); + if(line->text) + (line->text->delete)(line->text); free(line); line = next; } diff --git a/src/parser.c b/src/parser.c index 9721bd4..5b08be4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -174,21 +174,25 @@ deck_t *markdown_load(FILE *input) { deck->header = line; // find first non-header line - while(line->text->size > 0 && line->text->text[0] == '%') { + while(line && line->text->size > 0 && line->text->text[0] == '%') { hc++; line = line->next; } - // split linked list - line->prev->next = NULL; - line->prev = NULL; + // only split header if any non-header line is found + if(line) { - // remove header lines from slide - deck->slide->line = line; + // split linked list + line->prev->next = NULL; + line->prev = NULL; - // adjust counts - deck->headers += hc; - deck->slide->lines -= hc; + // remove header lines from slide + deck->slide->line = line; + + // adjust counts + deck->headers += hc; + deck->slide->lines -= hc; + } } slide = deck->slide;