[devhelp/wip/misc: 2/3] parser: avoid crash if the first element is <chapters> or <functions>



commit 7d1d62040a4408aaa76ece62092e852253fa985d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu May 11 18:19:40 2017 +0200

    parser: avoid crash if the first element is <chapters> or <functions>
    
    The first element must be <book>. Ensure that by moving the block of
    code starting with "if (parser->book_node == NULL)" at the beginning of
    the parser_start_node_cb() function.

 src/dh-parser.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/src/dh-parser.c b/src/dh-parser.c
index 5c05a3e..b728ce2 100644
--- a/src/dh-parser.c
+++ b/src/dh-parser.c
@@ -224,6 +224,8 @@ parser_start_node_chapter (DhParser             *parser,
                 return;
         }
 
+        g_assert (parser->book_node != NULL);
+
         link = dh_link_new (DH_LINK_TYPE_PAGE,
                             NULL,
                             NULL,
@@ -381,6 +383,9 @@ parser_start_node_keyword (DhParser             *parser,
                         link_type = DH_LINK_TYPE_ENUM;
         }
 
+        g_assert (parser->book_node != NULL);
+        g_assert (parser->parent != NULL);
+
         link = dh_link_new (link_type,
                             NULL,
                             NULL,
@@ -407,6 +412,16 @@ parser_start_node_cb (GMarkupParseContext  *context,
 {
         DhParser *parser = user_data;
 
+        if (parser->book_node == NULL) {
+                parser_start_node_book (parser,
+                                        context,
+                                        node_name,
+                                        attribute_names,
+                                        attribute_values,
+                                        error);
+                return;
+        }
+
         if (parser->parsing_keywords) {
                 parser_start_node_keyword (parser,
                                            context,
@@ -428,16 +443,6 @@ parser_start_node_cb (GMarkupParseContext  *context,
         } else if (g_ascii_strcasecmp (node_name, "chapters") == 0) {
                 parser->parsing_chapters = TRUE;
         }
-
-        if (parser->book_node == NULL) {
-                parser_start_node_book (parser,
-                                        context,
-                                        node_name,
-                                        attribute_names,
-                                        attribute_values,
-                                        error);
-                return;
-        }
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]