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:39 -0400 (EDT)

branch: master
commit 1a0c56f707a9fab44d58ec5d52ca9b67b9987f97
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 11 20:21:29 2024 +0200

    * tp/Texinfo/XS/main/parser_conf.h (PARSER_CONF): use size_t for the
    descriptor field.
    
    * tp/Texinfo/XS/main/build_perl_info.c (build_perl_*)
    (element_to_perl_hash, build_additional_info, store_source_mark_list)
    (build_tree_to_build, build_string_list, build_elements_list)
    (build_errors, add_formatted_error_messages)
    (build_target_elements_list, build_identifiers_target)
    (build_internal_xref_list, build_float_types_list)
    (build_single_index_data, build_global_info, build_global_commands)
    (output_unit_to_perl_hash, build_filenames, build_file_counters)
    (build_out_filepaths, build_output_files_unclosed_files)
    (build_output_files_opened_files),
    tp/Texinfo/XS/main/convert_to_texinfo.c (expand_cmd_args_to_texi)
    (convert_to_texinfo_internal), tp/Texinfo/XS/main/convert_to_text.c
    (convert_to_text_internal), tp/Texinfo/XS/main/convert_utils.c
    (find_innermost_accent_contents, definition_arguments_content)
    (definition_category_tree), tp/Texinfo/XS/main/debug.c,
    tp/Texinfo/XS/main/errors.c (wipe_error_messages),
    tp/Texinfo/XS/main/extra.c (get_associated_info_key)
    (lookup_associated_info, lookup_associated_info_by_index),
    tp/Texinfo/XS/main/get_perl_info.c (apply_sv_parser_conf)
    (find_index_entry_sv), tp/Texinfo/XS/main/node_name_normalization.c
    (convert_to_normalized_internal), tp/Texinfo/XS/main/parser_conf.c
    (retrieve_parser_conf): 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.
    
    * tp/Texinfo/XS/main/get_perl_info.c (add_svav_to_string_list): use
    SSize_t instead of size_t for consistency.
---
 ChangeLog                                    | 35 ++++++++++-
 tp/Texinfo/XS/main/build_perl_info.c         | 93 ++++++++++++++++++----------
 tp/Texinfo/XS/main/convert_to_texinfo.c      |  5 +-
 tp/Texinfo/XS/main/convert_to_text.c         |  6 +-
 tp/Texinfo/XS/main/convert_utils.c           |  6 +-
 tp/Texinfo/XS/main/debug.c                   | 10 +--
 tp/Texinfo/XS/main/errors.c                  |  2 +-
 tp/Texinfo/XS/main/extra.c                   | 11 ++--
 tp/Texinfo/XS/main/get_perl_info.c           |  8 +--
 tp/Texinfo/XS/main/node_name_normalization.c | 14 +++--
 tp/Texinfo/XS/main/parser_conf.c             |  2 +-
 tp/Texinfo/XS/main/parser_conf.h             |  6 +-
 tp/Texinfo/XS/parsetexi/Parsetexi.xs         |  4 +-
 13 files changed, 132 insertions(+), 70 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 39399f9399..5459c8a57c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2024-08-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/parser_conf.h (PARSER_CONF): use size_t for the
+       descriptor field.
+
+       * tp/Texinfo/XS/main/build_perl_info.c (build_perl_*)
+       (element_to_perl_hash, build_additional_info, store_source_mark_list)
+       (build_tree_to_build, build_string_list, build_elements_list)
+       (build_errors, add_formatted_error_messages)
+       (build_target_elements_list, build_identifiers_target)
+       (build_internal_xref_list, build_float_types_list)
+       (build_single_index_data, build_global_info, build_global_commands)
+       (output_unit_to_perl_hash, build_filenames, build_file_counters)
+       (build_out_filepaths, build_output_files_unclosed_files)
+       (build_output_files_opened_files),
+       tp/Texinfo/XS/main/convert_to_texinfo.c (expand_cmd_args_to_texi)
+       (convert_to_texinfo_internal), tp/Texinfo/XS/main/convert_to_text.c
+       (convert_to_text_internal), tp/Texinfo/XS/main/convert_utils.c
+       (find_innermost_accent_contents, definition_arguments_content)
+       (definition_category_tree), tp/Texinfo/XS/main/debug.c,
+       tp/Texinfo/XS/main/errors.c (wipe_error_messages),
+       tp/Texinfo/XS/main/extra.c (get_associated_info_key)
+       (lookup_associated_info, lookup_associated_info_by_index),
+       tp/Texinfo/XS/main/get_perl_info.c (apply_sv_parser_conf)
+       (find_index_entry_sv), tp/Texinfo/XS/main/node_name_normalization.c
+       (convert_to_normalized_internal), tp/Texinfo/XS/main/parser_conf.c
+       (retrieve_parser_conf): 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.
+       
+       * tp/Texinfo/XS/main/get_perl_info.c (add_svav_to_string_list): use
+       SSize_t instead of size_t for consistency.
+
 2024-08-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/multitable.c (gather_previous_item): rename
@@ -19,7 +52,7 @@
        tp/Texinfo/XS/structuring_transfo/structuring.c
        (insert_menu_comment_content, new_complete_node_menu): replace int by
        size_t in situations where the variable could reach a value outside of
-       the int range and also when the index is better reprensented by a
+       the int range and also when the index is better represented by a
        size_t.
 
 2024-08-11  Patrice Dumas  <pertusus@free.fr>
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 553f9efd2f..76cf399467 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -13,6 +13,14 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
+/* TODO there are many places where there is a theoretical possibility of 
overflow
+   if the size of a Perl array is not enough to accomodate the number of 
Texinfo
+   objects stored.  This is possible if max of SSize_t < max of size_t.  This 
is
+   only theoretical, though as these are big numbers, and according to internet
+   memory could be exhausted before reaching SSize_t.  It sould be checked
+   if the max of SSize_t was available, but it does not seems to be in Perl
+   documentation. */
+
 #include <config.h>
 #include <stdlib.h>
 #include <string.h>
@@ -182,7 +190,7 @@ build_perl_array (const ELEMENT_LIST *e_l, int 
avoid_recursion)
 {
   SV *sv;
   AV *av;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -215,7 +223,8 @@ build_perl_array (const ELEMENT_LIST *e_l, int 
avoid_recursion)
               element_to_perl_hash (e_l->list[i], avoid_recursion);
             }
         }
-      av_store (av, i, newRV_inc ((SV *) e_l->list[i]->hv));
+      /* NOTE theoretical overflow if max(SSize_t) < i */
+      av_store (av, (SSize_t) i, newRV_inc ((SV *) e_l->list[i]->hv));
     }
   return sv;
 }
@@ -225,7 +234,7 @@ build_perl_const_element_array (const CONST_ELEMENT_LIST 
*e_l, int avoid_recursi
 {
   SV *sv;
   AV *av;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -259,7 +268,8 @@ build_perl_const_element_array (const CONST_ELEMENT_LIST 
*e_l, int avoid_recursi
               element_to_perl_hash (f, avoid_recursion);
             }
         }
-      av_store (av, i, newRV_inc ((SV *) e_l->list[i]->hv));
+      /* NOTE theoretical overflow if max(SSize_t) < i */
+      av_store (av, (SSize_t) i, newRV_inc ((SV *) e_l->list[i]->hv));
     }
   return sv;
 }
@@ -287,7 +297,7 @@ build_perl_directions (const ELEMENT * const *e_l, int 
avoid_recursion)
 {
   SV *sv;
   HV *hv;
-  int d;
+  size_t d;
 
   dTHX;
 
@@ -353,7 +363,7 @@ build_additional_info (HV *extra, const ASSOCIATED_INFO *a,
 
   if (a->info_number > 0)
     {
-      int i;
+      size_t i;
 
       for (i = 0; i < a->info_number; i++)
         {
@@ -456,7 +466,7 @@ build_additional_info (HV *extra, const ASSOCIATED_INFO *a,
               av_unshift (av, l->number);
 
               STORE(newRV_inc ((SV *)av));
-              /* An array of strings or integers. */
+              /* An small array of strings. */
               for (j = 0; j < l->number; j++)
                 {
                   SV *sv = newSVpv_utf8 (l->list[j],
@@ -522,7 +532,7 @@ store_source_mark_list (const ELEMENT *e)
     {
       AV *av;
       SV *sv;
-      int i;
+      size_t i;
 
       if (e->source_mark_list->number == 0)
         {
@@ -603,6 +613,7 @@ store_source_mark_list (const ELEMENT *e)
                 break;
             }
 
+          /* NOTE theoretical overflow if max(SSize_t) < i */
           av_push (av, newRV_noinc ((SV *)source_mark));
 #undef STORE
         }
@@ -929,7 +940,7 @@ element_to_perl_hash (ELEMENT *e, int avoid_recursion)
   if (e->e.c->contents.number > 0)
     {
       AV *av;
-      int i;
+      size_t i;
 
       av = newAV ();
       sv = newRV_noinc ((SV *) av);
@@ -946,6 +957,7 @@ element_to_perl_hash (ELEMENT *e, int avoid_recursion)
          released when the element is destroyed, by calling
          unregister_perl_tree_element */
           sv = newRV_inc ((SV *) child->hv);
+         /* NOTE theoretical overflow if max(SSize_t) < i */
           av_store (av, i, sv);
         }
     }
@@ -953,7 +965,7 @@ element_to_perl_hash (ELEMENT *e, int avoid_recursion)
   if (e->e.c->args.number > 0)
     {
       AV *av;
-      int i;
+      size_t i;
 
       av = newAV ();
       sv = newRV_noinc ((SV *) av);
@@ -966,6 +978,7 @@ element_to_perl_hash (ELEMENT *e, int avoid_recursion)
           if (!child->hv || !avoid_recursion)
             element_to_perl_hash (child, avoid_recursion);
           sv = newRV_inc ((SV *) child->hv);
+          /* NOTE theoretical overflow if max(SSize_t) < i */
           av_store (av, i, sv);
         }
     }
@@ -1037,7 +1050,7 @@ build_tree_to_build (ELEMENT_LIST *tree_to_build)
 {
   if (tree_to_build->number > 0)
     {
-      int i;
+      size_t i;
       for (i = 0; i < tree_to_build->number; i++)
         {
           build_texinfo_tree (tree_to_build->list[i], 1);
@@ -1054,7 +1067,7 @@ AV *
 build_string_list (const STRING_LIST *strings_list, enum sv_string_type type)
 {
   AV *av;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1063,6 +1076,7 @@ build_string_list (const STRING_LIST *strings_list, enum 
sv_string_type type)
   for (i = 0; i < strings_list->number; i++)
     {
       const char *value = strings_list->list[i];
+      /* NOTE theoretical overflow if max(SSize_t) < i */
       if (!value)
         av_push (av, newSV (0));
       else if (type == svt_char)
@@ -1078,7 +1092,7 @@ build_elements_list (const CONST_ELEMENT_LIST *list)
 {
   AV *list_av;
   SV *sv;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1089,6 +1103,7 @@ build_elements_list (const CONST_ELEMENT_LIST *list)
   for (i = 0; i < list->number; i++)
     {
       sv = newRV_inc (list->list[i]->hv);
+      /* NOTE theoretical overflow if max(SSize_t) < i */
       av_store (list_av, i, sv);
     }
 
@@ -1100,7 +1115,7 @@ AV *
 build_integer_stack (const INTEGER_STACK *integer_stack)
 {
   AV *av;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1181,7 +1196,7 @@ AV *
 build_errors (const ERROR_MESSAGE *error_list, size_t error_number)
 {
   AV *av;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1190,6 +1205,7 @@ build_errors (const ERROR_MESSAGE *error_list, size_t 
error_number)
   for (i = 0; i < error_number; i++)
     {
       SV *sv = convert_error (error_list[i]);
+      /* NOTE theoretical overflow if max(SSize_t) < i */
       av_push (av, sv);
     }
 
@@ -1213,7 +1229,7 @@ add_formatted_error_messages (const ERROR_MESSAGE_LIST 
*error_messages,
 {
   SV **errors_warnings_sv;
   SV **error_nrs_sv;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1255,6 +1271,7 @@ add_formatted_error_messages (const ERROR_MESSAGE_LIST 
*error_messages,
               const ERROR_MESSAGE error_msg = error_messages->list[i];
               SV *sv = convert_error (error_msg);
 
+              /* NOTE theoretical overflow if max(SSize_t) < i */
               av_push (av, sv);
             }
 
@@ -1356,7 +1373,7 @@ build_target_elements_list (const LABEL_LIST *labels_list)
 {
   AV *target_array;
   SV *sv;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1366,6 +1383,7 @@ build_target_elements_list (const LABEL_LIST *labels_list)
   for (i = 0; i < labels_list->number; i++)
     {
       sv = newRV_inc (labels_list->list[i].element->hv);
+      /* NOTE theoretical overflow if max(SSize_t) < i */
       av_store (target_array, i, sv);
     }
 
@@ -1383,7 +1401,7 @@ build_identifiers_target (const LABEL_LIST 
*identifiers_target)
 
   if (identifiers_target->number > 0)
     {
-      int i;
+      size_t i;
       for (i = 0; i < identifiers_target->number; i++)
         {
           SV *sv = newRV_inc (identifiers_target->list[i].element->hv);
@@ -1400,7 +1418,7 @@ build_internal_xref_list (const ELEMENT_LIST 
*internal_xref_list)
 {
   AV *list_av;
   SV *sv;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1410,6 +1428,7 @@ build_internal_xref_list (const ELEMENT_LIST 
*internal_xref_list)
   for (i = 0; i < internal_xref_list->number; i++)
     {
       sv = newRV_inc (internal_xref_list->list[i]->hv);
+      /* NOTE theoretical overflow if max(SSize_t) < i */
       av_store (list_av, i, sv);
     }
 
@@ -1422,7 +1441,7 @@ build_float_types_list (const FLOAT_RECORD_LIST *floats)
 {
   HV *float_hash;
   SV *sv;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1454,6 +1473,7 @@ build_float_types_list (const FLOAT_RECORD_LIST *floats)
                         newRV_noinc ((SV *)av), 0);
         }
       sv = newRV_inc ((SV *)floats->list[i].element->hv);
+      /* NOTE theoretical overflow if max(SSize_t) < i */
       av_push (av, sv);
     }
 
@@ -1469,8 +1489,8 @@ build_single_index_data (const INDEX *index)
 
   HV *hv;
   AV *entries;
-  int j;
-  int entry_number;
+  size_t j;
+  size_t entry_number;
 
   dTHX;
 
@@ -1507,8 +1527,10 @@ build_single_index_data (const INDEX *index)
           if (e->entry_associated_element)
             STORE2("entry_associated_element",
                    newRV_inc ((SV *)e->entry_associated_element->hv));
-          STORE2("entry_number", newSViv (entry_number));
+          /* FIXME if there is some overflow here there is gonna be trouble */
+          STORE2("entry_number", newSViv ((IV) entry_number));
 
+          /* NOTE theoretical overflow if max(SSize_t) < j */
           av_store (entries, j, newRV_noinc ((SV *)entry));
 
           entry_number++;
@@ -1552,7 +1574,7 @@ build_global_info (const GLOBAL_INFO *global_info_ref,
   const GLOBAL_INFO global_info = *global_info_ref;
   const GLOBAL_COMMANDS global_commands = *global_commands_ref;
   const ELEMENT *document_language;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -1618,7 +1640,7 @@ build_global_commands (const GLOBAL_COMMANDS 
*global_commands_ref)
 {
   HV *hv;
   AV *av;
-  int i;
+  size_t i;
   const GLOBAL_COMMANDS global_commands = *global_commands_ref;
 
   dTHX;
@@ -1649,6 +1671,7 @@ build_global_commands (const GLOBAL_COMMANDS 
*global_commands_ref)
       for (i = 0; i < global_commands.dircategory_direntry.number; i++)
         {
           const ELEMENT *e = global_commands.dircategory_direntry.list[i];
+          /* NOTE theoretical overflow if max(SSize_t) < i */
           if (e->hv)
             av_push (av, newRV_inc ((SV *) e->hv));
         }
@@ -1664,6 +1687,7 @@ build_global_commands (const GLOBAL_COMMANDS 
*global_commands_ref)
       for (i = 0; i < global_commands.footnotes.number; i++)
         {
           const ELEMENT *e = global_commands.footnotes.list[i];
+          /* NOTE theoretical overflow if max(SSize_t) < i */
           if (e->hv)
             av_push (av, newRV_inc ((SV *) e->hv));
         }
@@ -1678,6 +1702,7 @@ build_global_commands (const GLOBAL_COMMANDS 
*global_commands_ref)
       for (i = 0; i < global_commands.floats.number; i++)
         {
           const ELEMENT *e = global_commands.floats.list[i];
+          /* NOTE theoretical overflow if max(SSize_t) < i */
           if (e->hv)
             av_push (av, newRV_inc ((SV *) e->hv));
         }
@@ -1692,6 +1717,7 @@ build_global_commands (const GLOBAL_COMMANDS 
*global_commands_ref)
       for (i = 0; i < global_commands.cmd.number; i++)             \
         {                                                               \
           const ELEMENT *e = global_commands.cmd.list[i];            \
+          /* NOTE theoretical overflow if max(SSize_t) < i */          \
           if (e->hv)                                                    \
             av_push (av, newRV_inc ((SV *) e->hv));                     \
         }                                                               \
@@ -2491,7 +2517,7 @@ output_unit_to_perl_hash (OUTPUT_UNIT *output_unit)
   if (output_unit->unit_contents.number)
     {
       AV *av;
-      int i;
+      size_t i;
 
       av = newAV ();
       sv = newRV_noinc ((SV *) av);
@@ -2507,6 +2533,7 @@ output_unit_to_perl_hash (OUTPUT_UNIT *output_unit)
 
           sv = newRV_inc ((SV *) element_hv);
 
+          /* NOTE theoretical overflow if max(SSize_t) < i */
           av_push (av, sv);
 
           unit_sv = newRV_inc ((SV *) output_unit->hv);
@@ -2519,8 +2546,8 @@ output_unit_to_perl_hash (OUTPUT_UNIT *output_unit)
   if (output_unit->tree_unit_directions[0]
       || output_unit->tree_unit_directions[1])
     {
-      int i;
-      int directions_nr = sizeof (output_unit->tree_unit_directions)
+      size_t i;
+      size_t directions_nr = sizeof (output_unit->tree_unit_directions)
                            / sizeof (output_unit->tree_unit_directions[0]);
       HV *hv_tree_unit_directions = newHV ();
       sv = newRV_noinc ((SV *) hv_tree_unit_directions);
@@ -3103,7 +3130,7 @@ pass_generic_converter_to_converter_sv (SV *converter_sv,
 static SV *
 build_filenames (const FILE_NAME_PATH_COUNTER_LIST *output_unit_files)
 {
-  int i;
+  size_t i;
   HV *hv;
 
   dTHX;
@@ -3131,7 +3158,7 @@ build_filenames (const FILE_NAME_PATH_COUNTER_LIST 
*output_unit_files)
 static SV *
 build_file_counters (const FILE_NAME_PATH_COUNTER_LIST *output_unit_files)
 {
-  int i;
+  size_t i;
   HV *hv;
 
   dTHX;
@@ -3157,7 +3184,7 @@ build_file_counters (const FILE_NAME_PATH_COUNTER_LIST 
*output_unit_files)
 SV *
 build_out_filepaths (const FILE_NAME_PATH_COUNTER_LIST *output_unit_files)
 {
-  int i;
+  size_t i;
   HV *hv;
 
   dTHX;
@@ -3217,7 +3244,7 @@ build_output_files_unclosed_files (HV *hv,
   HV *unclosed_files_hv;
 
   const FILE_STREAM_LIST *unclosed_files;
-  int i;
+  size_t i;
 
   dTHX;
 
@@ -3277,7 +3304,7 @@ build_output_files_opened_files (HV *hv,
   HV *opened_files_hv;
 
   const STRING_LIST *opened_files;
-  int i;
+  size_t i;
 
   dTHX;
 
diff --git a/tp/Texinfo/XS/main/convert_to_texinfo.c 
b/tp/Texinfo/XS/main/convert_to_texinfo.c
index bb067f07c3..db97f09eab 100644
--- a/tp/Texinfo/XS/main/convert_to_texinfo.c
+++ b/tp/Texinfo/XS/main/convert_to_texinfo.c
@@ -84,7 +84,8 @@ expand_cmd_args_to_texi (const ELEMENT *e, TEXT *result)
     }
   else if (e->e.c->args.number > 0)
     {
-      int braces, arg_nr, i;
+      size_t i, arg_nr;
+      int braces;
       int with_commas = 0;
 
       braces = (e->e.c->args.list[0]->type == ET_brace_container
@@ -175,7 +176,7 @@ convert_to_texinfo_internal (const ELEMENT *e, TEXT *result)
         }
       if (e->e.c->contents.number > 0)
         {
-          int i;
+          size_t i;
           for (i = 0; i < e->e.c->contents.number; i++)
             convert_to_texinfo_internal (e->e.c->contents.list[i], result);
         }
diff --git a/tp/Texinfo/XS/main/convert_to_text.c 
b/tp/Texinfo/XS/main/convert_to_text.c
index b84f6b49ff..ac39b0de40 100644
--- a/tp/Texinfo/XS/main/convert_to_text.c
+++ b/tp/Texinfo/XS/main/convert_to_text.c
@@ -813,7 +813,7 @@ convert_to_text_internal (const ELEMENT *element, 
TEXT_OPTIONS *text_options,
       else if ((builtin_command_data[data_cmd].flags & CF_brace)
                && builtin_command_data[data_cmd].data == BRACE_inline)
         {
-          int arg_index = 1;
+          size_t arg_index = 1;
           if (data_cmd == CM_inlineraw)
             text_options->raw_state++;
 
@@ -867,7 +867,7 @@ convert_to_text_internal (const ELEMENT *element, 
TEXT_OPTIONS *text_options,
         {
           if (element->e.c->args.number > 0)
             {
-              int i;
+              size_t i;
               TEXT args_line;
               text_init (&args_line);
               for (i = 0; i < element->e.c->args.number; i++)
@@ -1048,7 +1048,7 @@ convert_to_text_internal (const ELEMENT *element, 
TEXT_OPTIONS *text_options,
 
   if (element->e.c->contents.number)
     {
-      int i;
+      size_t i;
       int in_code = 0;
       int in_raw = 0;
       if ((data_cmd
diff --git a/tp/Texinfo/XS/main/convert_utils.c 
b/tp/Texinfo/XS/main/convert_utils.c
index db4eb4d3f7..0d3e45e390 100644
--- a/tp/Texinfo/XS/main/convert_utils.c
+++ b/tp/Texinfo/XS/main/convert_utils.c
@@ -129,7 +129,7 @@ find_innermost_accent_contents (const ELEMENT *element)
   while (1)
     {
       const ELEMENT *arg;
-      int i;
+      size_t i;
       enum command_id data_cmd;
       unsigned long flags;
 
@@ -473,7 +473,7 @@ definition_arguments_content (const ELEMENT *element)
   /* this condition is most probably always true */
   if (element->e.c->args.number > 0)
     {
-      int i;
+      size_t i;
       const ELEMENT *def_line = element->e.c->args.list[0];
       if (def_line->e.c->contents.number > 0)
         {
@@ -529,7 +529,7 @@ definition_category_tree (OPTIONS * options, const ELEMENT 
*current)
 
   if (current->e.c->args.number > 0)
     {
-      int i;
+      size_t i;
       const ELEMENT *def_line = current->e.c->args.list[0];
       for (i = 0; i < def_line->e.c->contents.number; i++)
         {
diff --git a/tp/Texinfo/XS/main/debug.c b/tp/Texinfo/XS/main/debug.c
index 923b412923..32df9ee5cf 100644
--- a/tp/Texinfo/XS/main/debug.c
+++ b/tp/Texinfo/XS/main/debug.c
@@ -123,7 +123,7 @@ char *
 print_associate_info_debug (const ASSOCIATED_INFO *info)
 {
   TEXT text;
-  int i;
+  size_t i;
 
   text_init (&text);
   text_append (&text, "");
@@ -161,7 +161,7 @@ print_associate_info_debug (const ASSOCIATED_INFO *info)
           }
         case extra_misc_args:
           {
-            int j;
+            size_t j;
             const STRING_LIST *l = k->k.strings_list;
             text_append (&text, "array: ");
             for (j = 0; j < l->number; j++)
@@ -179,7 +179,7 @@ print_associate_info_debug (const ASSOCIATED_INFO *info)
            }
         case extra_contents:
           {
-            int j;
+            size_t j;
             const CONST_ELEMENT_LIST *l = k->k.const_list;
             text_append (&text, "contents: ");
             for (j = 0; j < l->number; j++)
@@ -193,7 +193,7 @@ print_associate_info_debug (const ASSOCIATED_INFO *info)
           }
         case extra_directions:
           {
-            int d;
+            size_t d;
             const ELEMENT * const *l = k->k.directions;
             text_append (&text, "directions: ");
             for (d = 0; d < directions_length; d++)
@@ -211,7 +211,7 @@ print_associate_info_debug (const ASSOCIATED_INFO *info)
           }
         case extra_container:
           {
-            int j;
+            size_t j;
             const ELEMENT *f = k->k.element;
             text_append (&text, "contents: ");
             for (j = 0; j < f->e.c->contents.number; j++)
diff --git a/tp/Texinfo/XS/main/errors.c b/tp/Texinfo/XS/main/errors.c
index 10ac84b733..6dd16426b8 100644
--- a/tp/Texinfo/XS/main/errors.c
+++ b/tp/Texinfo/XS/main/errors.c
@@ -409,7 +409,7 @@ error_message_text (const ERROR_MESSAGE *error_msg, int 
use_filename,
 static void
 wipe_error_messages (ERROR_MESSAGE_LIST *error_messages)
 {
-  int j;
+  size_t j;
   for (j = 0; j < error_messages->number; j++)
     {
       free (error_messages->list[j].message);
diff --git a/tp/Texinfo/XS/main/extra.c b/tp/Texinfo/XS/main/extra.c
index 3b9880f59a..6f424f8da5 100644
--- a/tp/Texinfo/XS/main/extra.c
+++ b/tp/Texinfo/XS/main/extra.c
@@ -30,7 +30,7 @@ KEY_PAIR *
 get_associated_info_key (ASSOCIATED_INFO *a, enum ai_key_name key,
                          const enum extra_type type)
 {
-  int i;
+  size_t i;
   for (i = 0; i < a->info_number; i++)
     {
       if (a->info[i].key == key)
@@ -201,7 +201,7 @@ add_extra_integer (ELEMENT *e, enum ai_key_name key, int 
value)
 KEY_PAIR *
 lookup_associated_info (const ASSOCIATED_INFO *a, enum ai_key_name key)
 {
-  int i;
+  size_t i;
   for (i = 0; i < a->info_number; i++)
     {
       /* We could reuse extra_deleted slots by keeping the extra_deleted
@@ -398,12 +398,9 @@ lookup_extra_index_entry (const ELEMENT *e, enum 
ai_key_name key)
    for now */
 KEY_PAIR *
 lookup_associated_info_by_index (const ASSOCIATED_INFO *a,
-                                 enum ai_key_name key, int index)
+                                 enum ai_key_name key, size_t index)
 {
-  if (index < 0)
-    index = a->info_number + index;
-
-  if (index < 0 || index >= a->info_number)
+  if (index >= a->info_number)
     return 0;
 
   if (a->info[index].key == key)
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index b5cb113e1b..5a36d46f37 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -246,7 +246,7 @@ apply_sv_parser_conf (SV *parser_sv)
   parser_conf_descriptor_sv = hv_fetch (hv_in, key, strlen (key), 0);
   if (parser_conf_descriptor_sv && SvOK (*parser_conf_descriptor_sv))
     {
-      int parser_conf_descriptor = SvIV (*parser_conf_descriptor_sv);
+      size_t parser_conf_descriptor = (size_t) SvIV 
(*parser_conf_descriptor_sv);
 
       if (parser_conf_descriptor == global_parser_conf.descriptor)
         {
@@ -280,7 +280,7 @@ void
 add_svav_to_string_list (const SV *sv, STRING_LIST *string_list,
                          enum sv_string_type type)
 {
-  size_t i;
+  SSize_t i;
   SSize_t strings_nr;
 
   dTHX;
@@ -536,7 +536,7 @@ find_index_entry_sv (const SV *index_entry_sv, INDEX_LIST 
*indices_info,
   HV *index_entry_hv;
   SV **index_name_sv;
   SV **entry_number_sv;
-  int entry_idx_in_index;
+  size_t entry_idx_in_index;
   const char *entry_index_name = 0;
   const INDEX *idx;
 
@@ -558,7 +558,7 @@ find_index_entry_sv (const SV *index_entry_sv, INDEX_LIST 
*indices_info,
       fatal (msg);
     }
   entry_index_name = (const char *) SvPVutf8_nolen (*index_name_sv);
-  *entry_number = SvIV (*entry_number_sv);
+  *entry_number = (size_t) SvIV (*entry_number_sv);
   entry_idx_in_index = *entry_number - 1;
 
   idx = indices_info_index_by_name (indices_info, entry_index_name);
diff --git a/tp/Texinfo/XS/main/node_name_normalization.c 
b/tp/Texinfo/XS/main/node_name_normalization.c
index 42ef2f9f4a..bd36e2a876 100644
--- a/tp/Texinfo/XS/main/node_name_normalization.c
+++ b/tp/Texinfo/XS/main/node_name_normalization.c
@@ -117,19 +117,21 @@ convert_to_normalized_internal (const ELEMENT *e, TEXT 
*result)
         }
       else if (builtin_command_data[e->e.c->cmd].flags & CF_ref)
         {
-          int index = 0;
+          int order_index = 0;
           int *arguments_order = ref_5_args_order;
           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])
+              /* no risk with that casting as idx < 5 */
+              size_t idx = (size_t) arguments_order[order_index];
+              if (e->e.c->args.number > idx)
                 {
                   TEXT arg_text;
 
                   text_init (&arg_text);
                   convert_to_normalized_internal (
-                    e->e.c->args.list[arguments_order[index]], &arg_text);
+                    e->e.c->args.list[idx], &arg_text);
                   if (arg_text.end > 0)
                     {
                       char *non_space_char = arg_text.text
@@ -142,7 +144,7 @@ convert_to_normalized_internal (const ELEMENT *e, TEXT 
*result)
                         }
                     }
                 }
-              index++;
+              order_index++;
             }
         }
       else if (e->e.c->args.number > 0
@@ -156,7 +158,7 @@ convert_to_normalized_internal (const ELEMENT *e, TEXT 
*result)
     }
   if (e->e.c->contents.number > 0)
     {
-      int i;
+      size_t i;
       for (i = 0; i < e->e.c->contents.number; i++)
         convert_to_normalized_internal (e->e.c->contents.list[i], result);
     }
diff --git a/tp/Texinfo/XS/main/parser_conf.c b/tp/Texinfo/XS/main/parser_conf.c
index 06f6ab28e9..d5580546ac 100644
--- a/tp/Texinfo/XS/main/parser_conf.c
+++ b/tp/Texinfo/XS/main/parser_conf.c
@@ -45,7 +45,7 @@ static size_t parser_conf_space;
 
 
 PARSER_CONF *
-retrieve_parser_conf (int parser_conf_descriptor)
+retrieve_parser_conf (size_t parser_conf_descriptor)
 {
   if (parser_conf_descriptor <= parser_conf_number
       && parser_conf_list[parser_conf_descriptor -1] != 0)
diff --git a/tp/Texinfo/XS/main/parser_conf.h b/tp/Texinfo/XS/main/parser_conf.h
index d675cb548b..233acf9cfc 100644
--- a/tp/Texinfo/XS/main/parser_conf.h
+++ b/tp/Texinfo/XS/main/parser_conf.h
@@ -39,14 +39,14 @@ typedef struct PARSER_CONF {
     EXPANDED_FORMAT expanded_formats[7];
     VALUE_LIST values;
 
-    /* descriptor is the index in the array of registered conf */
-    int descriptor;
+    /* descriptor is the index +1 in the array of registered conf */
+    size_t descriptor;
 } PARSER_CONF;
 
 extern PARSER_CONF global_parser_conf;
 
 PARSER_CONF *register_conf (void);
-PARSER_CONF *retrieve_parser_conf (int parser_conf_descriptor);
+PARSER_CONF *retrieve_parser_conf (size_t parser_conf_descriptor);
 
 void clear_parser_conf (PARSER_CONF *parser_conf);
 
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index e24f90592b..19dd313e88 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -71,8 +71,10 @@ register_parser_conf (SV *parser)
     CODE:
       hv_in = (HV *)SvRV (parser);
       parser_conf = register_conf ();
+      /* FIXME parser_conf->descriptor is size_t, there will be an overflow
+         if parser_conf->descriptor > max of IV, which seems to be 
PERL_QUAD_MAX */
       hv_store (hv_in, key, strlen (key),
-                newSViv (parser_conf->descriptor), 0);
+                newSViv ((IV) parser_conf->descriptor), 0);
 
 # file path, can be in any encoding
 size_t



reply via email to

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