SHA256
3
0
forked from pool/texinfo
texinfo/texinfo-4.8-xml.patch

91 lines
2.9 KiB
Diff

--- makeinfo/xml.c
+++ makeinfo/xml.c 2007-02-19 14:53:37.000000000 +0100
@@ -30,6 +30,8 @@
#include "xml.h"
+#include <assert.h>
+
/* Options */
int xml_index_divisions = 1;
@@ -657,6 +659,7 @@ static int element_stack_index = 0;
static int
xml_current_element (void)
{
+ assert (element_stack_index > 0);
return element_stack[element_stack_index-1];
}
@@ -675,9 +678,10 @@ xml_pop_current_element (void)
{
element_stack_index--;
if (element_stack_index < 0)
- printf ("*** stack underflow (%d - %d) ***\n",
- element_stack_index,
- xml_current_element());
+ {
+ printf ("*** stack underflow (index %d) ***\n", element_stack_index);
+ element_stack_index = 0;
+ }
}
int
@@ -712,7 +716,8 @@ xml_start_para (void)
|| !xml_element_list[xml_current_element()].contains_para)
return;
- while (output_paragraph[output_paragraph_offset-1] == '\n')
+ while (output_paragraph_offset > 0
+ && output_paragraph[output_paragraph_offset-1] == '\n')
output_paragraph_offset--;
xml_indent ();
@@ -730,7 +735,8 @@ xml_end_para (void)
if (!xml_in_para || xml_in_footnote)
return;
- while (cr_or_whitespace(output_paragraph[output_paragraph_offset-1]))
+ while (output_paragraph_offset > 0
+ && cr_or_whitespace(output_paragraph[output_paragraph_offset-1]))
output_paragraph_offset--;
insert_string ("</para>");
@@ -789,7 +795,7 @@ xml_insert_element_with_attribute (elt,
/* Look at the replace_elements table to see if we have to change the element */
if (xml_sort_index)
return;
- if (docbook)
+ if (docbook && element_stack_index > 0)
{
replace_element *element_list = replace_elements;
while (element_list->element_to_replace >= 0)
@@ -905,13 +911,15 @@ xml_insert_element_with_attribute (elt,
/* Eat one newline before </example> and the like. */
if (!docbook && arg == END
&& (xml_element_list[elt].keep_space || elt == GROUP)
+ && output_paragraph_offset > 0
&& output_paragraph[output_paragraph_offset-1] == '\n')
output_paragraph_offset--;
/* And eat whitespace before </entry> in @multitables. */
if (arg == END && elt == ENTRY)
- while (cr_or_whitespace(output_paragraph[output_paragraph_offset-1]))
- output_paragraph_offset--;
+ while (output_paragraph_offset > 0 &&
+ cr_or_whitespace(output_paragraph[output_paragraph_offset-1]))
+ output_paragraph_offset--;
/* Indent elements that can contain <para>. */
if (arg == END && !xml_in_para && !xml_keep_space
@@ -1214,7 +1222,8 @@ xml_add_char (int character)
xml_just_after_element = 0;
}
- if (xml_element_list[xml_current_element()].contains_para
+ if (element_stack_index > 0
+ && xml_element_list[xml_current_element()].contains_para
&& !xml_in_para && !only_macro_expansion && !xml_no_para
&& !cr_or_whitespace (character) && !in_fixed_width_font)
xml_start_para ();