texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Sat, 7 May 2022 17:45:10 -0400 (EDT)

branch: master
commit 7f32763d96c5bc3b300932ab78662a41ee79bd31
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat May 7 21:02:11 2022 +0100

    Fix segfault for empty contents
    
    * tp/Texinfo/XS/misc.c (xs_merge_text): Check if the
    contents array was defined.
    * tp/Texinfo/XS/end_line.c (parse_node_manual): Remove confusing
    comment.
    
    Since recent change, there could be a segfault under
    TEXINFO_XS_PARSER=0 due to the contents array not being defined.
---
 ChangeLog                          | 12 +++++++++++
 tp/Texinfo/Common.pm               |  2 +-
 tp/Texinfo/XS/misc.c               | 44 ++++++++++++++++++++------------------
 tp/Texinfo/XS/parsetexi/end_line.c |  5 +----
 4 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6751973c5d..09057610c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-05-07  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Fix segfault for empty contents
+
+       * tp/Texinfo/XS/misc.c (xs_merge_text): Check if the
+       contents array was defined.
+       * tp/Texinfo/XS/end_line.c (parse_node_manual): Remove confusing
+       comment.
+
+       Since recent change, there could be a segfault under
+       TEXINFO_XS_PARSER=0 due to the contents array not being defined.
+
 2022-04-20  Patrice Dumas  <pertusus@free.fr>
 
        Fix both parsers to do the same tree with empty menu entry nodes
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 3c865edb1b..4ee6e2a34f 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1,6 +1,6 @@
 # Common.pm: definition of commands. Common code of other Texinfo modules.
 #
-# Copyright 2010-2020 Free Software Foundation, Inc.
+# Copyright 2010-2022 Free Software Foundation, Inc.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
diff --git a/tp/Texinfo/XS/misc.c b/tp/Texinfo/XS/misc.c
index 97bfc84b3a..91b4708fdd 100644
--- a/tp/Texinfo/XS/misc.c
+++ b/tp/Texinfo/XS/misc.c
@@ -274,29 +274,31 @@ xs_merge_text (HV *self, HV *current, SV *text_in)
           leading_spaces_sv = newSVpv (text, leading_spaces);
         }
 
-      svp = hv_fetch (current,
-                      "contents", strlen ("contents"), 0);
-      contents_array = (AV *)SvRV(*svp);
-      
-      contents_num = av_len(contents_array) + 1;
-      if (contents_num > 0)
+      svp = hv_fetch (current, "contents", strlen ("contents"), 0);
+      if (svp)
         {
-          HV *last_elt;
-          char *type = 0;
-
-          last_elt = (HV *)
-            SvRV (*av_fetch (contents_array, contents_num - 1, 0));
-
-          svp = hv_fetch (last_elt, "type", strlen ("type"), 0);
-          if (svp)
-            type = SvPV_nolen (*svp);
-          if (type
-              && (!strcmp (type, "empty_line_after_command")
-                  || !strcmp (type, "empty_spaces_after_command")
-                  || !strcmp (type, "empty_spaces_before_argument")
-                  || !strcmp (type, "empty_spaces_after_close_brace")))
+          contents_array = (AV *)SvRV(*svp);
+          
+          contents_num = av_len(contents_array) + 1;
+          if (contents_num > 0)
             {
-              no_merge_with_following_text = 1;
+              HV *last_elt;
+              char *type = 0;
+
+              last_elt = (HV *)
+                SvRV (*av_fetch (contents_array, contents_num - 1, 0));
+
+              svp = hv_fetch (last_elt, "type", strlen ("type"), 0);
+              if (svp)
+                type = SvPV_nolen (*svp);
+              if (type
+                  && (!strcmp (type, "empty_line_after_command")
+                      || !strcmp (type, "empty_spaces_after_command")
+                      || !strcmp (type, "empty_spaces_before_argument")
+                      || !strcmp (type, "empty_spaces_after_close_brace")))
+                {
+                  no_merge_with_following_text = 1;
+                }
             }
         }
 
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index 55f749e6ed..fcd725573d 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -813,10 +813,7 @@ kdbinputstyle_invalid:
    the 'menu_entry_node' key on a 'menu_entry' element (not to be confused
    with an ET_menu_entry_node element, which occurs in the args of a 
    'menu_entry' element), and in the 'node_argument' key of a cross-reference 
-   command (like @xref).
-
-   This function does not return 0 if there is no content for the node, as
-   the 'nodes_manuals' is delimited by a 0. */
+   command (like @xref). */
 NODE_SPEC_EXTRA *
 parse_node_manual (ELEMENT *node)
 {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]