]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Fix potential crash
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 30 Jul 2017 18:48:07 +0000 (14:48 -0400)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 30 Jul 2017 18:48:07 +0000 (14:48 -0400)
Sources/libMultiMarkdown/mmd.c

index 13859758e0b546c11772c7508a4442679bac2b16..70fe0a34f05e17641fe99f2e976f4a55b31e6b5a 100644 (file)
@@ -544,43 +544,48 @@ void mmd_assign_line_type(mmd_engine * e, token * line) {
                        break;
 
                case TEXT_NUMBER_POSS_LIST:
-                       switch (source[first_child->next->start]) {
-                               case ' ':
-                               case '\t':
-                                       line->type = LINE_LIST_ENUMERATED;
-                                       first_child->type = MARKER_LIST_ENUMERATOR;
-
-                                       switch (first_child->next->type) {
-                                               case TEXT_PLAIN:
-
-                                                       // Strip whitespace between bullet and text
-                                                       while (char_is_whitespace(source[first_child->next->start])) {
-                                                               first_child->next->start++;
-                                                               first_child->next->len--;
-                                                       }
+                       if (first_child->next) {
+                               switch (source[first_child->next->start]) {
+                                       case ' ':
+                                       case '\t':
+                                               line->type = LINE_LIST_ENUMERATED;
+                                               first_child->type = MARKER_LIST_ENUMERATOR;
 
-                                                       break;
+                                               switch (first_child->next->type) {
+                                                       case TEXT_PLAIN:
 
-                                               case INDENT_SPACE:
-                                               case INDENT_TAB:
-                                               case NON_INDENT_SPACE:
-                                                       t = first_child;
+                                                               // Strip whitespace between bullet and text
+                                                               while (char_is_whitespace(source[first_child->next->start])) {
+                                                                       first_child->next->start++;
+                                                                       first_child->next->len--;
+                                                               }
 
-                                                       while (t->next && ((t->next->type == INDENT_SPACE) ||
-                                                                          (t->next->type == INDENT_TAB) ||
-                                                                          (t->next->type == NON_INDENT_SPACE))) {
-                                                               tokens_prune(t->next, t->next);
-                                                       }
+                                                               break;
 
-                                                       break;
-                                       }
+                                                       case INDENT_SPACE:
+                                                       case INDENT_TAB:
+                                                       case NON_INDENT_SPACE:
+                                                               t = first_child;
 
-                                       break;
+                                                               while (t->next && ((t->next->type == INDENT_SPACE) ||
+                                                                                  (t->next->type == INDENT_TAB) ||
+                                                                                  (t->next->type == NON_INDENT_SPACE))) {
+                                                                       tokens_prune(t->next, t->next);
+                                                               }
 
-                               default:
-                                       line->type = LINE_PLAIN;
-                                       first_child->type = TEXT_PLAIN;
-                                       break;
+                                                               break;
+                                               }
+
+                                               break;
+
+                                       default:
+                                               line->type = LINE_PLAIN;
+                                               first_child->type = TEXT_PLAIN;
+                                               break;
+                               }
+                       } else {
+                               line->type = LINE_LIST_ENUMERATED;
+                               first_child->type = MARKER_LIST_ENUMERATOR;
                        }
 
                        break;