fixed header-only SEGV, closes #66
authorMichael Göhler <somebody.here@gmx.de>
Thu, 25 Dec 2014 05:24:05 +0000 (06:24 +0100)
committerMichael Göhler <somebody.here@gmx.de>
Thu, 25 Dec 2014 05:24:05 +0000 (06:24 +0100)
src/markdown.c
src/parser.c

index 22ebdbf..05c77be 100644 (file)
@@ -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;
     }
index 9721bd4..5b08be4 100644 (file)
@@ -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;