texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Fri, 4 Oct 2024 06:24:40 -0400 (EDT)

branch: master
commit 6912490d1852f1c5fb4a4135a0cb2562942e8586
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 11 22:54:28 2024 +0200

    * tp/Texinfo/XS/structuring_transfo/transformations.c
    (fill_gaps_in_sectioning, move_index_entries_after_items)
    (reassociate_to_node): use number of elements and size_t in a first
    step before setting the indices.
    
    * tp/Texinfo/XS/main/document.c (add_other_global_info_string),
    tp/Texinfo/XS/main/manipulate_indices.c
    (destroy_indices_sorted_by_letter, destroy_indices_sortable_entries)
    (sort_indices_by_letter),
    tp/Texinfo/XS/structuring_transfo/structuring.c (sectioning_structure)
    (warn_non_empty_parts, get_node_node_childs_from_sectioning)
    (check_nodes_are_referenced, set_menus_node_directions)
    (section_direction_associated_node, complete_node_tree_with_menus)
    (nodes_tree, associate_internal_references, new_node_menu_entry)
    (insert_menu_comment_content, new_complete_node_menu)
    (print_down_menus, new_detailmenu),
    tp/Texinfo/XS/structuring_transfo/transformations.c
    (lookup_index_entry, relate_index_entries_to_table_items_in)
    (move_index_entries_after_items, insert_nodes_for_sectioning_commands)
    (reference_to_arg_internal, complete_node_menu)
    (complete_tree_nodes_missing_menu, regenerate_master_menu): use size_t
    instead of int where the variable could reach a value outside of the
    int range and also when the index is better represented by a size_t.
---
 ChangeLog                                          |  26 +++++
 tp/Texinfo/XS/main/document.c                      |   2 +-
 tp/Texinfo/XS/main/manipulate_indices.c            |  11 +-
 tp/Texinfo/XS/main/tree_types.h                    |   2 +-
 tp/Texinfo/XS/structuring_transfo/structuring.c    |  84 ++++++++--------
 .../XS/structuring_transfo/transformations.c       | 111 +++++++++++----------
 6 files changed, 139 insertions(+), 97 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 75fd9eac1c..091378f448 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2024-08-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/structuring_transfo/transformations.c
+       (fill_gaps_in_sectioning, move_index_entries_after_items)
+       (reassociate_to_node): use number of elements and size_t in a first
+       step before setting the indices.
+
+       * tp/Texinfo/XS/main/document.c (add_other_global_info_string),
+       tp/Texinfo/XS/main/manipulate_indices.c
+       (destroy_indices_sorted_by_letter, destroy_indices_sortable_entries)
+       (sort_indices_by_letter),
+       tp/Texinfo/XS/structuring_transfo/structuring.c (sectioning_structure)
+       (warn_non_empty_parts, get_node_node_childs_from_sectioning)
+       (check_nodes_are_referenced, set_menus_node_directions)
+       (section_direction_associated_node, complete_node_tree_with_menus)
+       (nodes_tree, associate_internal_references, new_node_menu_entry)
+       (insert_menu_comment_content, new_complete_node_menu)
+       (print_down_menus, new_detailmenu),
+       tp/Texinfo/XS/structuring_transfo/transformations.c
+       (lookup_index_entry, relate_index_entries_to_table_items_in)
+       (move_index_entries_after_items, insert_nodes_for_sectioning_commands)
+       (reference_to_arg_internal, complete_node_menu)
+       (complete_tree_nodes_missing_menu, regenerate_master_menu): use size_t
+       instead of int where the variable could reach a value outside of the
+       int range and also when the index is better represented by a size_t.
+
 2024-08-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/utils.c (get_encoding_conversion): use a separate
diff --git a/tp/Texinfo/XS/main/document.c b/tp/Texinfo/XS/main/document.c
index 4e0cfc5e0c..3b80ebc1d6 100644
--- a/tp/Texinfo/XS/main/document.c
+++ b/tp/Texinfo/XS/main/document.c
@@ -564,7 +564,7 @@ void
 add_other_global_info_string (OTHER_GLOBAL_INFO *other_global_info,
                               const char *key, const char *value)
 {
-  int i;
+  size_t i;
   for (i = 0; i < other_global_info->info_number; i++)
     {
       if (!strcmp (other_global_info->info[i].key, key))
diff --git a/tp/Texinfo/XS/main/manipulate_indices.c 
b/tp/Texinfo/XS/main/manipulate_indices.c
index 12ad29805b..9e98647d0c 100644
--- a/tp/Texinfo/XS/main/manipulate_indices.c
+++ b/tp/Texinfo/XS/main/manipulate_indices.c
@@ -165,7 +165,7 @@ destroy_indices_sorted_by_letter (
 
   for (index = indices_entries_by_letter; index->name; index++)
     {
-      int i;
+      size_t i;
       free (index->name);
       for (i = 0; i < index->letter_number; i++)
         {
@@ -852,6 +852,7 @@ compare_sortable_index_entry_wrapper (const void *a, const 
void *b)
   return compare_sortable_index_entry (sie_a, sie_b);
 }
 
+/* the entry is not destroyed here as it is transferred to the sorted indices 
*/
 static void
 destroy_indices_sortable_entries (
              INDICES_SORTABLE_ENTRIES *indices_sortable_entries)
@@ -909,7 +910,7 @@ sort_indices_by_index (DOCUMENT *document, 
ERROR_MESSAGE_LIST *error_messages,
                        const char *collation_locale)
 {
   size_t i;
-  int index_nr = 0;
+  size_t index_nr = 0;
   INDEX_COLLATOR *collator;
 
   INDICES_SORTABLE_ENTRIES *indices_sortable_entries
@@ -961,7 +962,9 @@ sort_indices_by_index (DOCUMENT *document, 
ERROR_MESSAGE_LIST *error_messages,
       index_nr++;
     }
 
+  /* add a 0 at the end of the list */
   memset (&sorted_index_entries[index_nr], 0, sizeof (INDEX_SORTED_BY_INDEX));
+  /* shrink the list if there are less sorted indices than sortable indices */
   if (index_nr < indices_sortable_entries->number)
     sorted_index_entries = realloc (sorted_index_entries,
                      (index_nr+1) * sizeof (INDEX_SORTED_BY_INDEX));
@@ -980,7 +983,7 @@ sort_indices_by_letter (DOCUMENT *document, 
ERROR_MESSAGE_LIST *error_messages,
                         const char *collation_locale)
 {
   size_t i;
-  int index_nr = 0;
+  size_t index_nr = 0;
   static INDEX_LETTERS_SORTABLE_ENTRIES index_letters_sortable_entries;
   INDEX_COLLATOR *collator;
 
@@ -1212,7 +1215,9 @@ sort_indices_by_letter (DOCUMENT *document, 
ERROR_MESSAGE_LIST *error_messages,
       index_nr++;
     }
 
+  /* add a 0 at the end of the list */
   memset (&sorted_index_entries[index_nr], 0, sizeof (INDEX_SORTED_BY_LETTER));
+  /* shrink the list if there are less sorted indices than sortable indices */
   if (index_nr < indices_sortable_entries->number)
     sorted_index_entries = realloc (sorted_index_entries,
                      (index_nr+1) * sizeof (INDEX_SORTED_BY_LETTER));
diff --git a/tp/Texinfo/XS/main/tree_types.h b/tp/Texinfo/XS/main/tree_types.h
index a966c5a928..85aaf2296b 100644
--- a/tp/Texinfo/XS/main/tree_types.h
+++ b/tp/Texinfo/XS/main/tree_types.h
@@ -213,7 +213,7 @@ typedef struct CONST_ELEMENT_LIST {
    should outlive the INDEX_ENTRY_LOCATION */
 typedef struct INDEX_ENTRY_LOCATION {
     const char *index_name;
-    int number; /* position in the original index.  May be different in
+    size_t number; /* position in the original index.  May be different in
                    merged index */
 } INDEX_ENTRY_LOCATION;
 
diff --git a/tp/Texinfo/XS/structuring_transfo/structuring.c 
b/tp/Texinfo/XS/structuring_transfo/structuring.c
index 8b6c7c2d6d..4e4a3801b2 100644
--- a/tp/Texinfo/XS/structuring_transfo/structuring.c
+++ b/tp/Texinfo/XS/structuring_transfo/structuring.c
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stddef.h>
 
 #include "text.h"
 #include "element_types.h"
@@ -89,7 +90,7 @@ sectioning_structure (DOCUMENT *document)
   int number_top_level = 0;
   CONST_ELEMENT_LIST *sections_list = new_const_element_list ();
   const ELEMENT *section_top = 0;
-  int i;
+  size_t i;
   TEXT section_number;
   text_init (&section_number);
 
@@ -400,7 +401,7 @@ warn_non_empty_parts (DOCUMENT *document)
   ERROR_MESSAGE_LIST *error_messages = &document->error_messages;
   OPTIONS *options = document->options;
 
-  int i;
+  size_t i;
 
   for (i = 0; i < global_commands->part.number; i++)
     {
@@ -467,7 +468,7 @@ get_node_node_childs_from_sectioning (const ELEMENT *node)
                                             AI_key_section_childs);
       if (section_childs)
         {
-          int i;
+          size_t i;
           for (i = 0; i < section_childs->number; i++)
             {
               const ELEMENT *child = section_childs->list[i];
@@ -497,7 +498,7 @@ get_node_node_childs_from_sectioning (const ELEMENT *node)
                        = lookup_extra_contents (current, 
AI_key_section_childs);
                       if (section_childs)
                         {
-                          int i;
+                          size_t i;
                           for (i = 0; i < section_childs->number; i++)
                             {
                               const ELEMENT *child = section_childs->list[i];
@@ -616,7 +617,8 @@ check_nodes_are_referenced (DOCUMENT *document)
       int is_target = (node->flags & EF_is_target);
       const ELEMENT * const *node_directions = lookup_extra_directions (node,
                                                    AI_key_node_directions);
-      const CONST_ELEMENT_LIST *menus = lookup_extra_contents (node, 
AI_key_menus);
+      const CONST_ELEMENT_LIST *menus
+        = lookup_extra_contents (node, AI_key_menus);
 
       if (is_target)
         nr_nodes_to_find++;
@@ -624,7 +626,7 @@ check_nodes_are_referenced (DOCUMENT *document)
       /* gather referenced nodes based on node pointers */
       if (node_directions)
         {
-          int d;
+          size_t d;
           for (d = 0; d < directions_length; d++)
             {
               if (node_directions[d])
@@ -637,11 +639,11 @@ check_nodes_are_referenced (DOCUMENT *document)
         }
       if (menus)
         {
-          int j;
+          size_t j;
           for (j = 0; j < menus->number; j++)
             {
               const ELEMENT *menu = menus->list[j];
-              int k;
+              size_t k;
               for (k = 0; k < menu->e.c->contents.number; k++)
                 {
                   const ELEMENT *menu_content = menu->e.c->contents.list[k];
@@ -671,7 +673,7 @@ check_nodes_are_referenced (DOCUMENT *document)
             {
               CONST_ELEMENT_LIST *node_childs
                 = get_node_node_childs_from_sectioning (node);
-              int j;
+              size_t j;
               for (j = 0; j < node_childs->number; j++)
                 {
                   referenced_identifiers =
@@ -688,7 +690,7 @@ check_nodes_are_referenced (DOCUMENT *document)
   /* consider nodes in internal @*ref commands to be referenced */
   if (refs)
     {
-      int i;
+      size_t i;
       for (i = 0; i < refs->number; i++)
         {
           ELEMENT *ref = refs->list[i];
@@ -810,7 +812,7 @@ set_menus_node_directions (DOCUMENT *document)
   OPTIONS *options = document->options;
 
   int check_menu_entries = 1;
-  int i;
+  size_t i;
 
   if (!nodes_list || nodes_list->number <= 0)
     return;
@@ -831,7 +833,7 @@ set_menus_node_directions (DOCUMENT *document)
 
   for (i = 0; i < nodes_list->number; i++)
     {
-      int j;
+      size_t j;
       const ELEMENT *node = nodes_list->list[i];
       const CONST_ELEMENT_LIST *menus = lookup_extra_contents (node, 
AI_key_menus);
 
@@ -855,14 +857,14 @@ set_menus_node_directions (DOCUMENT *document)
         {
           const ELEMENT *menu = menus->list[j];
           ELEMENT *previous_node = 0;
-          int k;
+          size_t k;
           for (k = 0; k < menu->e.c->contents.number; k++)
             {
               const ELEMENT *menu_content = menu->e.c->contents.list[k];
               if (menu_content->type == ET_menu_entry)
                 {
                   ELEMENT *menu_node = 0;
-                  int l;
+                  size_t l;
                   for (l = 0; l < menu_content->e.c->contents.number; l++)
                     {
                       const ELEMENT *content
@@ -937,17 +939,17 @@ set_menus_node_directions (DOCUMENT *document)
   /* Check @detailmenu */
   if (check_menu_entries && global_commands->detailmenu.number > 0)
     {
-      int i;
+      size_t i;
       for (i = 0; i < global_commands->detailmenu.number; i++)
         {
           const ELEMENT *detailmenu = global_commands->detailmenu.list[i];
-          int k;
+          size_t k;
           for (k = 0; k < detailmenu->e.c->contents.number; k++)
             {
               const ELEMENT *menu_content = detailmenu->e.c->contents.list[k];
               if (menu_content->type == ET_menu_entry)
                 {
-                  int l;
+                  size_t l;
                   for (l = 0; l < menu_content->e.c->contents.number; l++)
                     {
                       const ELEMENT *content = 
menu_content->e.c->contents.list[l];
@@ -977,7 +979,7 @@ static const ELEMENT *
 section_direction_associated_node (const ELEMENT *section,
                                    enum directions direction)
 {
-  int i;
+  size_t i;
   for (i = 0; i < sizeof (direction_bases) / sizeof (direction_bases[0]);
        i++)
     {
@@ -1011,7 +1013,7 @@ complete_node_tree_with_menus (DOCUMENT *document)
   ERROR_MESSAGE_LIST *error_messages = &document->error_messages;
   OPTIONS *options = document->options;
 
-  int i;
+  size_t i;
   const ELEMENT *top_node = 0;
   const ELEMENT *top_node_next = 0;
 
@@ -1039,7 +1041,7 @@ complete_node_tree_with_menus (DOCUMENT *document)
                                               AI_key_node_directions);
           if (strcmp (normalized, "Top"))
             {
-              int d;
+              size_t d;
               for (d = 0; d < directions_length; d++)
                 {
                   const ELEMENT *section;
@@ -1166,7 +1168,7 @@ complete_node_tree_with_menus (DOCUMENT *document)
               else
                 {
                   /* use the first non top node as next for Top */
-                  int j;
+                  size_t j;
                   for (j = 0; j < nodes_list->number; j++)
                     {
                       const ELEMENT *first_non_top_node
@@ -1203,7 +1205,7 @@ complete_node_tree_with_menus (DOCUMENT *document)
                                                       AI_key_node_directions);
           if (node_directions && menu_directions)
             {
-              int d;
+              size_t d;
               for (d = 0; d < directions_length; d++)
                 {
                   if (node_directions[d]
@@ -1266,12 +1268,12 @@ complete_node_tree_with_menus (DOCUMENT *document)
                /* check only if there are menus */
                   && menus)
                 {
-                  int j;
+                  size_t j;
                   int found = 0;
                   for (j = 0; j < menus->number; j++)
                     {
                       const ELEMENT *menu = menus->list[j];
-                      int k;
+                      size_t k;
                       for (k = 0; k < menu->e.c->contents.number; k++)
                         {
                           const ELEMENT *menu_content = 
menu->e.c->contents.list[k];
@@ -1319,7 +1321,7 @@ nodes_tree (DOCUMENT *document)
   const ELEMENT *top_node_section_child = 0;
   CONST_ELEMENT_LIST *nodes_list = new_const_element_list ();
 
-  int i;
+  size_t i;
 
   for (i = 0; i < root->e.c->contents.number; i++)
     {
@@ -1410,11 +1412,11 @@ nodes_tree (DOCUMENT *document)
           }
       else /* explicit directions */
         {
-          int i;
+          size_t i;
           for (i = 1; i < node->e.c->args.number; i++)
             {
               const ELEMENT *direction_element = node->e.c->args.list[i];
-              int direction = i - 1;
+              int direction = (int) i - 1;
               const ELEMENT *manual_content
                             = lookup_extra_container (direction_element,
                                                     AI_key_manual_content);
@@ -1499,7 +1501,7 @@ associate_internal_references (DOCUMENT *document)
   ERROR_MESSAGE_LIST *error_messages = &document->error_messages;
   OPTIONS *options = document->options;
 
-  int i;
+  size_t i;
 
   if (!refs || !refs->number)
     return;
@@ -1682,7 +1684,7 @@ new_node_menu_entry (const ELEMENT *node, int 
use_sections)
   ELEMENT *description_text;
   ELEMENT *menu_entry_leading_text;
   NODE_SPEC_EXTRA *parsed_entry_node;
-  int i;
+  size_t i;
   int is_target = (node->flags & EF_is_target);
   if (is_target)
     node_name_element = node->e.c->args.list[0];
@@ -1692,7 +1694,7 @@ new_node_menu_entry (const ELEMENT *node, int 
use_sections)
 
   if (use_sections)
     {
-      int i;
+      size_t i;
       ELEMENT *name_element;
       const ELEMENT *associated_section
         = lookup_extra_element (node, AI_key_associated_section);
@@ -1798,7 +1800,7 @@ insert_menu_comment_content (ELEMENT_LIST *element_list, 
size_t position,
   ELEMENT *empty_line_first_after = new_text_element (ET_empty_line);
   ELEMENT *empty_line_second_after = new_text_element (ET_empty_line);
   int index_in_preformatted = 0;
-  int i;
+  size_t i;
 
   add_to_element_contents (menu_comment, preformatted);
 
@@ -1833,7 +1835,7 @@ new_complete_node_menu (const ELEMENT *node, DOCUMENT 
*document,
     = get_node_node_childs_from_sectioning (node);
   const ELEMENT *section;
   ELEMENT *new_menu;
-  int i;
+  size_t i;
 
   if (node_childs->number <= 0)
     {
@@ -1949,7 +1951,7 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
   CONST_ELEMENT_LIST *node_menus = lookup_extra_contents (node, AI_key_menus);
   ELEMENT_LIST *node_children;
   ELEMENT *new_current_menu = 0;
-  int i;
+  size_t i;
 
   if (node_menus && node_menus->number > 0)
     menus = node_menus;
@@ -1972,7 +1974,7 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
   for (i = 0; i < menus->number; i++)
     {
       const ELEMENT *menu = menus->list[i];
-      int j;
+      size_t j;
       for (j = 0; j < menu->e.c->contents.number; j++)
         {
           ELEMENT *entry = menu->e.c->contents.list[j];
@@ -2031,12 +2033,12 @@ print_down_menus (const ELEMENT *node, ELEMENT_STACK 
*up_nodes,
           ELEMENT_LIST *child_menu_content;
           const char *normalized_child
             = lookup_extra_string (child, AI_key_normalized);
-          size_t i;
+          size_t j;
           int up_node_in_menu = 0;
 
-          for (i = 0; i < up_nodes->top; i++)
+          for (j = 0; j < up_nodes->top; j++)
             {
-              const ELEMENT *up_node = up_nodes->stack[i];
+              const ELEMENT *up_node = up_nodes->stack[j];
               const char *normalized_up_node
                 = lookup_extra_string (up_node, AI_key_normalized);
               if (!strcmp (normalized_child, normalized_up_node))
@@ -2094,11 +2096,11 @@ new_detailmenu (ERROR_MESSAGE_LIST *error_messages,
 
   if (menus && menus->number > 0)
     {
-      int i;
+      size_t i;
       for (i = 0; i < menus->number; i++)
         {
           const ELEMENT *menu = menus->list[i];
-          int j;
+          size_t j;
           for (j = 0; j < menu->e.c->contents.number; j++)
             {
               const ELEMENT *entry = menu->e.c->contents.list[j];
@@ -2114,7 +2116,7 @@ new_detailmenu (ERROR_MESSAGE_LIST *error_messages,
                                           identifiers_target, use_sections);
                       if (down_menus)
                         {
-                          int k;
+                          size_t k;
                           for (k = 0; k < down_menus->number; k++)
                             down_menus->list[k]->parent = new_detailmenu_e;
                           insert_list_slice_into_contents (new_detailmenu_e,
@@ -2129,7 +2131,7 @@ new_detailmenu (ERROR_MESSAGE_LIST *error_messages,
     }
   if (new_detailmenu_e->e.c->contents.number > 0)
     {
-      int i;
+      size_t i;
       ELEMENT *new_line = new_text_element (ET_normal_text);
     /* There is a menu comment with a preformatted added in front of each
        detailed menu section with the node section name */
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c 
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index 8230f1341a..f8d927db4f 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -55,7 +55,7 @@ lookup_index_entry (const INDEX_ENTRY_LOCATION 
*index_entry_info,
                     INDEX_LIST *indices_info)
 {
   INDEX_ENTRY_AND_INDEX *result = 0;
-  int entry_number = index_entry_info->number;
+  size_t entry_number = index_entry_info->number;
   const char *entry_index_name = index_entry_info->index_name;
   INDEX *index_info;
 
@@ -79,7 +79,7 @@ lookup_index_entry (const INDEX_ENTRY_LOCATION 
*index_entry_info,
 void
 protect_first_parenthesis (ELEMENT *element)
 {
-  int i;
+  size_t i;
 
   if (element->e.c->contents.number <= 0)
     return;
@@ -195,9 +195,10 @@ ELEMENT_LIST *
 fill_gaps_in_sectioning (ELEMENT *root, ELEMENT *commands_heading_content)
 {
   ELEMENT_LIST *added_sections = new_list ();
-  int idx_current_section = -1;
-  int idx_next_section = -1;
+  size_t nr_current_section = 0;
+  size_t nr_next_section = 0;
   size_t idx = 0;
+  size_t idx_current_section, idx_next_section;
 
   while (idx < root->e.c->contents.number)
     {
@@ -208,22 +209,25 @@ fill_gaps_in_sectioning (ELEMENT *root, ELEMENT 
*commands_heading_content)
       if (!data_cmd || data_cmd == CM_node || !(CF_root & flags))
         {
         }
-      else if (idx_current_section < 0)
-        idx_current_section = idx;
-      else if (idx_next_section < 0)
+      else if (nr_current_section == 0)
+        nr_current_section = idx +1;
+      else if (nr_next_section == 0)
         {
-          idx_next_section = idx;
+          nr_next_section = idx +1;
           break;
         }
       idx++;
     }
 
-  if (idx_current_section < 0)
+  if (nr_current_section == 0)
     return 0;
 
-  if (idx_next_section < 0)
+  if (nr_next_section == 0)
     return added_sections;
 
+  idx_current_section = nr_current_section -1;
+  idx_next_section = nr_next_section -1;
+
   while (1)
     {
       ELEMENT *current_section = root->e.c->contents.list[idx_current_section];
@@ -316,7 +320,7 @@ void
 relate_index_entries_to_table_items_in (ELEMENT *table,
                                         INDEX_LIST *indices_info)
 {
-  int i;
+  size_t i;
 
   if (table->e.c->contents.number <= 0)
     return;
@@ -343,7 +347,7 @@ relate_index_entries_to_table_items_in (ELEMENT *table,
           && table_entry->e.c->contents.list[1]->type == ET_table_definition)
         {
           size_t nr_index_entry_command = 0;
-          int j;
+          size_t j;
           definition = table_entry->e.c->contents.list[1];
 
           for (j = 0; j < definition->e.c->contents.number; j++)
@@ -368,7 +372,7 @@ relate_index_entries_to_table_items_in (ELEMENT *table,
       if (term->type == ET_table_term)
         {
           INDEX_ENTRY_AND_INDEX *entry_idx_info = 0;
-          int j;
+          size_t j;
          /*
          Relate the first index_entry_command in the 'table_term' to
          the term itself.
@@ -453,7 +457,7 @@ void
 move_index_entries_after_items (ELEMENT *current)
 {
   ELEMENT *previous = 0;
-  int i;
+  size_t i;
 
   for (i = 0; i < current->e.c->contents.number; i++)
     {
@@ -464,8 +468,8 @@ move_index_entries_after_items (ELEMENT *current)
         {
           ELEMENT *previous_ending_container;
           ELEMENT *prev_last_child = last_contents_child (previous);
-          int last_entry_idx = -1;
-          int j;
+          size_t last_entry_nr = 0;
+          size_t j;
           size_t contents_nr;
 
           if (prev_last_child->type == ET_paragraph
@@ -475,20 +479,23 @@ move_index_entries_after_items (ELEMENT *current)
             previous_ending_container = previous;
 
           contents_nr = previous_ending_container->e.c->contents.number;
-          for (j = contents_nr - 1; j >= 0; j--)
+          for (j = contents_nr; j > 0; j--)
             {
-              ELEMENT *content = 
previous_ending_container->e.c->contents.list[j];
+              ELEMENT *content
+                = previous_ending_container->e.c->contents.list[j-1];
               if (content->type == ET_index_entry_command)
-                last_entry_idx = j;
+                last_entry_nr = j;
               else if ((!(type_data[content->type].flags & TF_at_command))
                        || (content->e.c->cmd != CM_comment
                            && content->e.c->cmd != CM_c))
                 break;
             }
 
-          if (last_entry_idx >= 0)
+          if (last_entry_nr > 0)
             {
               size_t insertion_idx = 0;
+              size_t last_entry_idx = last_entry_nr -1;
+              size_t k;
               ELEMENT *item_container;
 
               if (item->e.c->contents.number
@@ -497,8 +504,8 @@ move_index_entries_after_items (ELEMENT *current)
               else
                 item_container = item;
 
-              for (j = last_entry_idx; j < contents_nr; j++)
-                previous_ending_container->e.c->contents.list[j]->parent
+              for (k = last_entry_idx; k < contents_nr; k++)
+                previous_ending_container->e.c->contents.list[k]->parent
                   = item_container;
 
               if (item_container->e.c->contents.number
@@ -627,7 +634,7 @@ new_node (ERROR_MESSAGE_LIST *error_messages, ELEMENT 
*node_tree,
 
   while (1)
     {
-      int i;
+      size_t i;
       char *non_hyphen_char;
       ELEMENT *target = 0;
       ELEMENT *appended_text = 0;
@@ -702,24 +709,25 @@ reassociate_to_node (const char *type, ELEMENT *current, 
void *argument)
         {
           CONST_ELEMENT_LIST *menus
             = lookup_extra_contents (previous_node, AI_key_menus);
-          int previous_idx = -1;
+          size_t previous_nr = 0;
           if (menus)
             {
-              int i;
+              size_t i;
               for (i = 0; i < menus->number; i++)
                 {
                   if (menus->list[i] == current)
                     {
-                      previous_idx = i;
+                      previous_nr = i + 1;
                       break;
                     }
                 }
             }
-          if (previous_idx < 0)
+          if (previous_nr == 0)
             fprintf (stderr, "BUG: menu %p not in previous node %p\n",
                              current, previous_node);
           else
             {
+              size_t previous_idx = previous_nr -1;
               /* removed element should be current */
               remove_from_const_element_list (menus, previous_idx);
               if (menus->number <= 0)
@@ -779,7 +787,7 @@ insert_nodes_for_sectioning_commands (DOCUMENT *document)
 {
   ELEMENT *root = document->tree;
   ELEMENT_LIST *added_nodes = new_list ();
-  int idx;
+  size_t idx;
   ELEMENT *previous_node = 0;
 
   for (idx = 0; idx < root->e.c->contents.number; idx++)
@@ -861,7 +869,7 @@ reference_to_arg_internal (const char *type,
       && builtin_command_data[e->e.c->cmd].flags & CF_ref)
     {
       DOCUMENT *document = (DOCUMENT *) argument;
-      int index = 0;
+      int order_index = 0;
       int *arguments_order = ref_5_args_order;
       /* container for the new elements to insert, will be destroyed
          by the caller */
@@ -871,11 +879,12 @@ reference_to_arg_internal (const char *type,
       add_to_element_list (container, new);
       if (e->e.c->cmd == CM_inforef || e->e.c->cmd == CM_link)
         arguments_order = ref_3_args_order;
-      while (arguments_order[index] >= 0)
+      while (arguments_order[order_index] >= 0)
         {
-          if (e->e.c->args.number > arguments_order[index])
+          size_t idx = (size_t) arguments_order[order_index];
+          if (e->e.c->args.number > idx)
             {
-              ELEMENT *arg = e->e.c->args.list[arguments_order[index]];
+              ELEMENT *arg = e->e.c->args.list[idx];
             /*
              this will not detect if the content expands as spaces only, like
              @asis{ }, @ , but it is not an issue or could even be considered
@@ -883,9 +892,8 @@ reference_to_arg_internal (const char *type,
              */
               if (!is_content_empty (arg, 0))
                 {
-                  ELEMENT *removed
-                      = remove_from_args (e, arguments_order[index]);
-                  int i;
+                  ELEMENT *removed = remove_from_args (e, idx);
+                  size_t i;
                   if (removed != arg)
                     fatal ("BUG: reference_to_arg_internal removed != arg");
                   /* avoid the type and spaces by getting only the contents */
@@ -898,7 +906,7 @@ reference_to_arg_internal (const char *type,
                   break;
                 }
             }
-          index++;
+          order_index++;
         }
       if (document && document->internal_references.number > 0)
         {
@@ -950,15 +958,16 @@ complete_node_menu (ELEMENT *node, int use_sections)
 
   if (node_childs->number)
     {
-      int existing_entries_nr = 0;
-      int existing_entries_space = 5;
+      size_t existing_entries_nr = 0;
+      size_t existing_entries_space = 5;
       EXISTING_ENTRY *existing_entries = 0;
 
       ELEMENT_LIST *pending = new_list ();
       ELEMENT *current_menu = 0;
 
-      int i;
-      const CONST_ELEMENT_LIST *menus = lookup_extra_contents (node, 
AI_key_menus);
+      size_t i;
+      const CONST_ELEMENT_LIST *menus
+        = lookup_extra_contents (node, AI_key_menus);
 
       if (menus)
         {
@@ -969,7 +978,7 @@ complete_node_menu (ELEMENT *node, int use_sections)
             {
               /* cast to remove the const, as the menu is to be modified */
               ELEMENT *menu = (ELEMENT *)menus->list[i];
-              int j;
+              size_t j;
               for (j = 0; j < menu->e.c->contents.number; j++)
                 {
                   ELEMENT *entry = menu->e.c->contents.list[j];
@@ -1003,7 +1012,7 @@ complete_node_menu (ELEMENT *node, int use_sections)
                                                         AI_key_normalized);
           if (normalized)
             {
-              int j;
+              size_t j;
               ELEMENT *entry = 0;
 
               for (j = 0; j < existing_entries_nr; j++)
@@ -1019,7 +1028,7 @@ complete_node_menu (ELEMENT *node, int use_sections)
                 {
                   if (pending->number)
                     {
-                      int k;
+                      size_t k;
                       for (j = 0; j < current_menu->e.c->contents.number; j++)
                       if (current_menu->e.c->contents.list[j] == entry)
                         break;
@@ -1047,7 +1056,7 @@ complete_node_menu (ELEMENT *node, int use_sections)
 
       if (pending->number)
         {
-          int j;
+          size_t j;
           if (!current_menu)
             {
   /* cast to remove const, as the section is modified, with the new menu
@@ -1092,7 +1101,7 @@ static ELEMENT_LIST *
 get_non_automatic_nodes_with_sections (const ELEMENT *root)
 {
   ELEMENT_LIST *non_automatic_nodes = new_list ();
-  int i;
+  size_t i;
 
   for (i = 0; i < root->e.c->contents.number; i++)
     {
@@ -1115,7 +1124,7 @@ complete_tree_nodes_menus (const ELEMENT *root, int 
use_sections)
 {
   ELEMENT_LIST *non_automatic_nodes
      = get_non_automatic_nodes_with_sections (root);
-  int i;
+  size_t i;
   for (i = 0; i < non_automatic_nodes->number; i++)
     {
       ELEMENT *node = non_automatic_nodes->list[i];
@@ -1131,7 +1140,7 @@ complete_tree_nodes_missing_menu (DOCUMENT *document, int 
use_sections)
   OPTIONS *options = document->options;
   ELEMENT_LIST *non_automatic_nodes
      = get_non_automatic_nodes_with_sections (root);
-  int i;
+  size_t i;
   for (i = 0; i < non_automatic_nodes->number; i++)
     {
       ELEMENT *node = non_automatic_nodes->list[i];
@@ -1164,8 +1173,8 @@ regenerate_master_menu (DOCUMENT *document, int 
use_sections)
   ELEMENT *new_detailmenu_e;
   ELEMENT *last_menu;
   const ELEMENT *last_content;
-  int i;
-  int index;
+  size_t i;
+  size_t index;
 
   if (top_node)
     {
@@ -1188,7 +1197,7 @@ regenerate_master_menu (DOCUMENT *document, int 
use_sections)
 
   for (i = 0; i < menus->number; i++)
     {
-      int detailmenu_index = 0;
+      size_t detailmenu_index = 0;
       /* cast to remove const to be able to replace the detailmenu */
       ELEMENT *menu = (ELEMENT *)menus->list[i];
       for (detailmenu_index = 0; detailmenu_index < menu->e.c->contents.number;
@@ -1324,7 +1333,7 @@ protect_hashchar_at_line_beginning_internal (const char 
*type,
       by a new line
       */
           ELEMENT *parent = current->parent;
-          int i;
+          size_t i;
 
           if (filename)
             free (filename);



reply via email to

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