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 e521320042d3dd93c993a9691f6b765c6b1290e9
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Aug 11 21:44:37 2024 +0200

    * tp/Texinfo/XS/main/utils.c (get_encoding_conversion): use a separate
    variable for utf8_missing case.  Use size_t encoding_nr to find he
    number of the encoding, using 0 for not found.  Also use size_t for
    encoding_index and set it when the case is known.
    
    * tp/Texinfo/XS/parsetexi/macro.c (lookup_macro_parameter)
    (expand_macro_body): have lookup_macro_parameter return index of
    argument +1, to be able to return a size_t and use 0 for not found.
    
    * tp/Texinfo/XS/convert/ConvertXS.xs (get_unclosed_stream)
    (html_close_registered_sections_level, html_get_css_elements_classes)
    (html_register_footnote), tp/Texinfo/XS/convert/get_html_perl_info.c
    (html_converter_initialize_sv, html_set_shared_conversion_state),
    tp/Texinfo/XS/convert/texinfo.c (txi_parser),
    tp/Texinfo/XS/main/build_perl_info.c (build_expanded_formats),
    tp/Texinfo/XS/main/get_perl_info.c (apply_sv_parser_conf)
    (html_get_button_specification_list, find_root_command)
    (find_element_from_sv), tp/Texinfo/XS/main/translations.c
    (replace_substrings, substitute_element_array)
    (replace_convert_substrings), tp/Texinfo/XS/main/unicode.c
    (encoded_accents, unicode_point_decoded_in_encoding),
    tp/Texinfo/XS/main/utils.c (reset_encoding_list)
    (clear_expanded_formats, add_expanded_format, format_expanded_p)
    (expanded_formats_number, locate_include_file, clear_strings_list)
    (delete_global_info, get_global_document_command, is_content_empty),
    tp/Texinfo/XS/parsetexi/close.c (close_command_cleanup),
    tp/Texinfo/XS/parsetexi/commands.c (lookup_command)
    (wipe_user_commands), tp/Texinfo/XS/parsetexi/def.c (parse_def),
    tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line)
    (end_line_starting_block, end_line_misc_line),
    tp/Texinfo/XS/parsetexi/handle_commands.c (check_no_text)
    (handle_line_command), tp/Texinfo/XS/parsetexi/indices.c
    (space_for_indices, associate_command_to_index, init_index_commands)
    (set_non_ignored_space_in_index_before_command, complete_indices),
    tp/Texinfo/XS/parsetexi/macro.c (lookup_macro, expand_macro_arguments)
    (expand_linemacro_arguments, wipe_macros, handle_macro, store_value)
    (clear_value, fetch_value, lookup_infoenclose, add_infoenclose),
    tp/Texinfo/XS/parsetexi/menus.c
    (register_extra_menu_entry_information, end_line_menu_entry),
    tp/Texinfo/XS/parsetexi/parser.c (text_contents_to_plain_text)
    (merge_text), tp/Texinfo/XS/parsetexi/separator.c
    (check_empty_expansion): 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                                  | 47 +++++++++++++++++++++++++++
 tp/Texinfo/XS/convert/ConvertXS.xs         | 10 +++---
 tp/Texinfo/XS/convert/get_html_perl_info.c |  6 ++--
 tp/Texinfo/XS/convert/texinfo.c            |  2 +-
 tp/Texinfo/XS/main/build_perl_info.c       |  4 ++-
 tp/Texinfo/XS/main/get_perl_info.c         | 14 ++++----
 tp/Texinfo/XS/main/translations.c          |  8 ++---
 tp/Texinfo/XS/main/unicode.c               |  8 ++---
 tp/Texinfo/XS/main/utils.c                 | 45 ++++++++++++++------------
 tp/Texinfo/XS/main/utils.h                 |  2 +-
 tp/Texinfo/XS/parsetexi/close.c            |  6 ++--
 tp/Texinfo/XS/parsetexi/commands.c         |  4 +--
 tp/Texinfo/XS/parsetexi/def.c              |  4 +--
 tp/Texinfo/XS/parsetexi/end_line.c         | 13 +++++---
 tp/Texinfo/XS/parsetexi/handle_commands.c  |  6 ++--
 tp/Texinfo/XS/parsetexi/indices.c          | 12 +++----
 tp/Texinfo/XS/parsetexi/macro.c            | 51 ++++++++++++++++--------------
 tp/Texinfo/XS/parsetexi/menus.c            |  4 +--
 tp/Texinfo/XS/parsetexi/parser.c           |  7 ++--
 tp/Texinfo/XS/parsetexi/separator.c        |  2 +-
 20 files changed, 159 insertions(+), 96 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5459c8a57c..75fd9eac1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,50 @@
+2024-08-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/utils.c (get_encoding_conversion): use a separate
+       variable for utf8_missing case.  Use size_t encoding_nr to find he
+       number of the encoding, using 0 for not found.  Also use size_t for
+       encoding_index and set it when the case is known.
+
+       * tp/Texinfo/XS/parsetexi/macro.c (lookup_macro_parameter)
+       (expand_macro_body): have lookup_macro_parameter return index of
+       argument +1, to be able to return a size_t and use 0 for not found.
+
+       * tp/Texinfo/XS/convert/ConvertXS.xs (get_unclosed_stream)
+       (html_close_registered_sections_level, html_get_css_elements_classes)
+       (html_register_footnote), tp/Texinfo/XS/convert/get_html_perl_info.c
+       (html_converter_initialize_sv, html_set_shared_conversion_state),
+       tp/Texinfo/XS/convert/texinfo.c (txi_parser),
+       tp/Texinfo/XS/main/build_perl_info.c (build_expanded_formats),
+       tp/Texinfo/XS/main/get_perl_info.c (apply_sv_parser_conf)
+       (html_get_button_specification_list, find_root_command)
+       (find_element_from_sv), tp/Texinfo/XS/main/translations.c
+       (replace_substrings, substitute_element_array)
+       (replace_convert_substrings), tp/Texinfo/XS/main/unicode.c
+       (encoded_accents, unicode_point_decoded_in_encoding),
+       tp/Texinfo/XS/main/utils.c (reset_encoding_list)
+       (clear_expanded_formats, add_expanded_format, format_expanded_p)
+       (expanded_formats_number, locate_include_file, clear_strings_list)
+       (delete_global_info, get_global_document_command, is_content_empty),
+       tp/Texinfo/XS/parsetexi/close.c (close_command_cleanup),
+       tp/Texinfo/XS/parsetexi/commands.c (lookup_command)
+       (wipe_user_commands), tp/Texinfo/XS/parsetexi/def.c (parse_def),
+       tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line)
+       (end_line_starting_block, end_line_misc_line),
+       tp/Texinfo/XS/parsetexi/handle_commands.c (check_no_text)
+       (handle_line_command), tp/Texinfo/XS/parsetexi/indices.c
+       (space_for_indices, associate_command_to_index, init_index_commands)
+       (set_non_ignored_space_in_index_before_command, complete_indices),
+       tp/Texinfo/XS/parsetexi/macro.c (lookup_macro, expand_macro_arguments)
+       (expand_linemacro_arguments, wipe_macros, handle_macro, store_value)
+       (clear_value, fetch_value, lookup_infoenclose, add_infoenclose),
+       tp/Texinfo/XS/parsetexi/menus.c
+       (register_extra_menu_entry_information, end_line_menu_entry),
+       tp/Texinfo/XS/parsetexi/parser.c (text_contents_to_plain_text)
+       (merge_text), tp/Texinfo/XS/parsetexi/separator.c
+       (check_empty_expansion): 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/parser_conf.h (PARSER_CONF): use size_t for the
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index cb6b20fece..3f54463d33 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -489,7 +489,7 @@ get_unclosed_stream (SV *converter_in, file_path)
          unclosed_files = &output_files_information->unclosed_files;
          if (unclosed_files->number > 0)
            {
-             int i;
+             size_t i;
              for (i = 0; i < unclosed_files->number; i++)
                {
                  FILE_STREAM *file_stream = &unclosed_files->list[i];
@@ -2235,7 +2235,7 @@ html_close_registered_sections_level (SV *converter_in, 
filename, int level)
 
              if (closed_elements->number > 0)
                {
-                 int i;
+                 size_t i;
                  for (i = 0; i < closed_elements->number; i++)
                    {
                      SV *close_string_sv
@@ -2308,7 +2308,7 @@ html_get_css_elements_classes (SV *converter_in, ...)
                {
                  if (result->number)
                    {
-                     int i;
+                     size_t i;
                      for (i = 0; i < result->number; i++)
                        {
                          SV *selector_sv
@@ -2428,8 +2428,8 @@ html_register_footnote (SV *converter_in, SV *command, 
footid, docid, int number
                                 strlen ("global_command_number"), 0);
                  if (global_command_number_sv)
                    {
-                     int global_command_number
-                       = SvIV (*global_command_number_sv);
+                     size_t global_command_number
+                       = (size_t) SvIV (*global_command_number_sv);
                      if (global_command_number > 0
                          && global_command_number - 1 < footnotes->number)
                        {
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c 
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index 1ffae6c8d1..54d1814814 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -234,7 +234,7 @@ html_converter_initialize_sv (SV *converter_sv,
                               SV *customized_direction_strings
                              )
 {
-  int i;
+  size_t i;
   HV *converter_hv;
   HV *default_formatting_references_hv;
   HV *default_css_string_formatting_references_hv;
@@ -1191,7 +1191,7 @@ html_converter_initialize_sv (SV *converter_sv,
 
           if (SvOK (stage_sv))
             {
-              size_t k;
+              SSize_t k;
               AV *stage_av = (AV *)SvRV (stage_sv);
               HTML_STAGE_HANDLER_INFO_LIST *stage_handler_list
                 = &converter->html_stage_handlers[stage];
@@ -1792,7 +1792,7 @@ html_set_shared_conversion_state (CONVERTER *converter, 
SV *converter_in,
       int number = SvIV (args_sv[1]);
       if (converter->document && converter->document->listoffloats.number > 0)
         {
-          int i;
+          size_t i;
           const LISTOFFLOATS_TYPE_LIST
             *listoffloats = &converter->document->listoffloats;
           for (i = 0; i < listoffloats->number; i++)
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index 3cb47c25c7..5dfafe8405 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -62,7 +62,7 @@ txi_parser (const char *file_path, const char 
*locale_encoding,
 {
   char *input_file_name_and_directory[2];
   char *input_directory;
-  int i;
+  size_t i;
   int debug = 0;
   int includes_set = 0;
 
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 76cf399467..5f3bc4e60f 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -2465,6 +2465,8 @@ output_unit_to_perl_hash (OUTPUT_UNIT *output_unit)
         return;
     }
 
+  /* FIXME output_unit->index is size_t, there will be an overflow if
+     output_unit->index > max of IV */
   sv = newSViv ((IV) output_unit->index);
   STORE("unit_index");
 
@@ -2739,7 +2741,7 @@ output_units_list_to_perl_hash (const DOCUMENT *document,
 static HV *
 build_expanded_formats (const EXPANDED_FORMAT *expanded_formats)
 {
-  int i;
+  size_t i;
   HV *expanded_hv;
 
   dTHX;
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index 5a36d46f37..1bbce52d04 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -246,7 +246,8 @@ 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))
     {
-      size_t parser_conf_descriptor = (size_t) 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)
         {
@@ -265,7 +266,7 @@ apply_sv_parser_conf (SV *parser_sv)
 
       if (!parser_conf)
         {
-          fprintf (stderr, "ERROR: get_sv_parser_conf: descriptor %d not 
found\n",
+          fprintf (stderr, "ERROR: get_sv_parser_conf: descriptor %zu not 
found\n",
                            parser_conf_descriptor);
           return;
         }
@@ -882,7 +883,7 @@ html_get_button_specification_list (const CONVERTER 
*converter,
   BUTTON_SPECIFICATION_LIST *result;
   AV *buttons_av;
   SSize_t buttons_nr;
-  SSize_t i;
+  size_t i;
 
   dTHX;
 
@@ -915,7 +916,7 @@ html_get_button_specification_list (const CONVERTER 
*converter,
 
   for (i = 0; i < result->number; i++)
     {
-      SV **button_sv = av_fetch (result->av, i, 0);
+      SV **button_sv = av_fetch (result->av, (SSize_t) i, 0);
       BUTTON_SPECIFICATION *button = &result->list[i];
 
       if (!button_sv || !SvOK (*button_sv))
@@ -1256,7 +1257,7 @@ find_root_command (const DOCUMENT *document, HV 
*element_hv,
 
           if (unit_index_sv)
             {
-              int unit_index = SvIV (*unit_index_sv);
+              size_t unit_index = (size_t) SvIV (*unit_index_sv);
               const OUTPUT_UNIT_LIST *output_units
                = retrieve_output_units (document, output_units_descriptor);
 
@@ -1464,7 +1465,8 @@ find_element_from_sv (const CONVERTER *converter, const 
DOCUMENT *document_in,
           EXTRA(global_command_number)
           if (global_command_number_sv)
             {
-              int global_command_number = SvIV (*global_command_number_sv);
+              size_t global_command_number
+                = (size_t) SvIV (*global_command_number_sv);
               const ELEMENT_LIST *global_cmd_list
                 = get_cmd_global_multi_command (
                               &document->global_commands, cmd);
diff --git a/tp/Texinfo/XS/main/translations.c 
b/tp/Texinfo/XS/main/translations.c
index c7ef343656..2bda5c835f 100644
--- a/tp/Texinfo/XS/main/translations.c
+++ b/tp/Texinfo/XS/main/translations.c
@@ -351,7 +351,7 @@ replace_substrings (const char *string,
             {
               if (*(q + flag_len) == '}')
                 {
-                  int i;
+                  size_t i;
                   char *flag = strndup (q, flag_len);
 
                   /* past } */
@@ -390,7 +390,7 @@ void
 substitute_element_array (ELEMENT_LIST *list,
                           NAMED_STRING_ELEMENT_LIST *replaced_substrings)
 {
-  int idx = 0;
+  size_t idx = 0;
 
   for (; idx < list->number; idx++)
     {
@@ -401,7 +401,7 @@ substitute_element_array (ELEMENT_LIST *list,
             {
               char *name = e->e.c->args.list[0]->e.c->contents.list[0]
                                                             ->e.text->text;
-              int i;
+              size_t i;
               for (i = 0; i < replaced_substrings->number; i++)
                 {
                   if (!strcmp (name, replaced_substrings->list[i].name))
@@ -436,7 +436,7 @@ replace_convert_substrings (char *translated_string,
                             NAMED_STRING_ELEMENT_LIST *replaced_substrings,
                             int debug_level)
 {
-  int i;
+  size_t i;
   char *texinfo_line;
   size_t document_descriptor;
   int parser_debug_level = 0;
diff --git a/tp/Texinfo/XS/main/unicode.c b/tp/Texinfo/XS/main/unicode.c
index f3d1e601dd..2ef09e842c 100644
--- a/tp/Texinfo/XS/main/unicode.c
+++ b/tp/Texinfo/XS/main/unicode.c
@@ -384,7 +384,7 @@ encoded_accents (CONVERTER *self, const char *text, const 
ELEMENT_STACK *stack,
       if (possible_encoding)
         {
           int encoding_index = -1;
-          int i;
+          size_t i;
           if (!strcmp (normalized_encoding, "utf-8"))
             {
               free (normalized_encoding);
@@ -427,7 +427,7 @@ int unicode_point_decoded_in_encoding (const char *encoding,
                                       (encoding, &possible_encoding);
       if (possible_encoding)
         {
-          int i;
+          size_t i;
           if (!strcmp (normalized_encoding, "utf-8"))
             {
               free (normalized_encoding);
@@ -444,7 +444,7 @@ int unicode_point_decoded_in_encoding (const char *encoding,
                   if (point_nr < 127)
                     {
                       free (normalized_encoding);
-                      return i + 1;
+                      return (int) i + 1;
                     }
                   char *found = (char *)bsearch (&codepoint,
                              unicode_to_eight_bit[i].codepoints,
@@ -453,7 +453,7 @@ int unicode_point_decoded_in_encoding (const char *encoding,
                   if (found)
                     {
                       free (normalized_encoding);
-                      return i + 1;
+                      return (int) i + 1;
                     }
                   break;
                 }
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 50cb31ae9d..a165255ebe 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -368,7 +368,9 @@ get_encoding_conversion (const char *encoding,
                          ENCODING_CONVERSION_LIST *encodings_list)
 {
   const char *conversion_encoding = encoding;
-  int encoding_index = -1;
+  size_t encoding_nr = 0;
+  size_t encoding_index = 0;
+  int utf8_missing = 0;
 
   /* should correspond to
      Texinfo::Common::encoding_name_conversion_map.
@@ -381,31 +383,30 @@ get_encoding_conversion (const char *encoding,
   if (!strcasecmp (encoding, "utf-8"))
     {
       if (encodings_list->number > 0)
-        encoding_index = 0;
+        encoding_nr = 1;
       else
-        encoding_index = -2;
+        utf8_missing = 1;
     }
   else if (encodings_list->number > 1)
     {
-      int i;
+      size_t i;
       for (i = 1; i < encodings_list->number; i++)
         {
           if (!strcasecmp (conversion_encoding,
                            encodings_list->list[i].encoding_name))
             {
-              encoding_index = i;
+              encoding_nr = i+1;
               break;
             }
         }
     }
 
-  if (encoding_index < 0)
+  if (encoding_nr == 0)
     {
       if (encodings_list->number == 0)
         encodings_list->number++;
-      if (encoding_index == -2) /* utf-8 */
-        encoding_index = 0;
-      else
+
+      if (!utf8_missing) /* !utf-8 */
         {
           encoding_index = encodings_list->number;
           encodings_list->number++;
@@ -416,7 +417,6 @@ get_encoding_conversion (const char *encoding,
           encodings_list->list = realloc (encodings_list->list,
               (encodings_list->space += 3) * sizeof (ENCODING_CONVERSION));
         }
-
       encodings_list->list[encoding_index].encoding_name
            = strdup (conversion_encoding);
       /* Initialize conversions for the first time.  iconv_open returns
@@ -428,6 +428,8 @@ get_encoding_conversion (const char *encoding,
         encodings_list->list[encoding_index].iconv
            = iconv_open (conversion_encoding, "UTF-8");
     }
+  else
+   encoding_index = encoding_nr - 1;
 
   if (encodings_list->list[encoding_index].iconv == (iconv_t) -1)
     return 0;
@@ -443,7 +445,7 @@ get_encoding_conversion (const char *encoding,
 void
 reset_encoding_list (ENCODING_CONVERSION_LIST *encodings_list)
 {
-  int i;
+  size_t i;
   /* never reset the utf-8 encoding in position 0 */
   if (encodings_list->number > 1)
     {
@@ -589,7 +591,7 @@ encode_string (char *input_string, const char *encoding, 
int *status,
 void
 clear_expanded_formats (EXPANDED_FORMAT *formats)
 {
-  int i;
+  size_t i;
   for (i = 0; i < sizeof (default_expanded_formats)
                             / sizeof (*default_expanded_formats);
        i++)
@@ -601,7 +603,7 @@ clear_expanded_formats (EXPANDED_FORMAT *formats)
 void
 add_expanded_format (EXPANDED_FORMAT *formats, const char *format)
 {
-  int i;
+  size_t i;
   for (i = 0; i < sizeof (default_expanded_formats)
                       / sizeof (*default_expanded_formats);
        i++)
@@ -629,7 +631,7 @@ new_expanded_formats (void)
 int
 format_expanded_p (const EXPANDED_FORMAT *formats, const char *format)
 {
-  int i;
+  size_t i;
   for (i = 0; i < sizeof (default_expanded_formats)
                            / sizeof (*default_expanded_formats);
        i++)
@@ -640,7 +642,7 @@ format_expanded_p (const EXPANDED_FORMAT *formats, const 
char *format)
   return 0;
 }
 
-int
+size_t
 expanded_formats_number (void)
 {
   return sizeof (default_expanded_formats)
@@ -1038,7 +1040,8 @@ locate_include_file (const char *filename, const 
STRING_LIST *include_dirs_list)
 {
   char *fullpath;
   struct stat dummy;
-  int i, status;
+  int status;
+  size_t i;
 
   /* Checks if filename is absolute or relative to current directory. */
   /* Note: the Perl code (in Common.pm, 'locate_include_file') handles
@@ -1072,7 +1075,7 @@ locate_include_file (const char *filename, const 
STRING_LIST *include_dirs_list)
 void
 clear_strings_list (STRING_LIST *strings)
 {
-  int i;
+  size_t i;
   for (i = 0; i < strings->number; i++)
     {
       free (strings->list[i]);
@@ -1146,7 +1149,7 @@ wipe_values (VALUE_LIST *values)
 void
 delete_global_info (GLOBAL_INFO *global_info)
 {
-  int i;
+  size_t i;
   free_strings_list (&global_info->included_files);
 
   free (global_info->input_encoding_name);
@@ -1246,7 +1249,7 @@ informative_command_value (const ELEMENT *element)
       else if (element->e.c->args.number > 0)
         {
           TEXT text;
-          int i;
+          size_t i;
           char *text_seen = 0;
           for (i = 0; i < element->e.c->args.number; i++)
             {
@@ -1372,7 +1375,7 @@ get_global_document_command (const GLOBAL_COMMANDS 
*global_commands,
                 }
               else
                 {
-                  int i;
+                  size_t i;
                   for (i = 0; i < command_list->number; i++)
                     {
                       ELEMENT *command_element = command_list->list[i];
@@ -1477,7 +1480,7 @@ section_level_adjusted_command_name (const ELEMENT 
*element)
 int
 is_content_empty (const ELEMENT *tree, int do_not_ignore_index_entries)
 {
-  int i;
+  size_t i;
   if (!tree || !tree->e.c->contents.number)
     return 1;
 
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 5a967f206c..a66de63aea 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -230,7 +230,7 @@ EXPANDED_FORMAT *new_expanded_formats (void);
 void clear_expanded_formats (EXPANDED_FORMAT *formats);
 void add_expanded_format (EXPANDED_FORMAT *formats, const char *format);
 int format_expanded_p (const EXPANDED_FORMAT *formats, const char *format);
-int expanded_formats_number (void);
+size_t expanded_formats_number (void);
 void set_expanded_formats_from_options (EXPANDED_FORMAT *formats,
                                         const OPTIONS *options);
 
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 0e5ce530ee..3ec8fcca26 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -225,7 +225,8 @@ close_command_cleanup (ELEMENT *current)
 
   if (current->e.c->cmd == CM_multitable)
     {
-      int in_head_or_rows = -1, i;
+      int in_head_or_rows = -1;
+      size_t i;
       ELEMENT_LIST old_contents = current->e.c->contents;
 
       /* Clear current contents. */
@@ -319,7 +320,8 @@ close_command_cleanup (ELEMENT *current)
           if (current->e.c->contents.number == 1)
             {
        /* no @*item, only before_item.  Warn if before_item is not empty */
-              int empty_before_item = 1, i;
+              int empty_before_item = 1;
+              size_t i;
               /* Check if contents consist solely of @comment's. */
               for (i = 0; i < before_item->e.c->contents.number; i++)
                 {
diff --git a/tp/Texinfo/XS/parsetexi/commands.c 
b/tp/Texinfo/XS/parsetexi/commands.c
index 49ee241542..98df12ac64 100644
--- a/tp/Texinfo/XS/parsetexi/commands.c
+++ b/tp/Texinfo/XS/parsetexi/commands.c
@@ -36,7 +36,7 @@ enum command_id
 lookup_command (const char *cmdname)
 {
   enum command_id cmd;
-  int i;
+  size_t i;
 
   /* Check for user-defined commands: macros, indexes, etc. */
   /* Do this before looking in the built-in commands, in case the user uses
@@ -130,7 +130,7 @@ remove_texinfo_command (enum command_id cmd)
 void
 wipe_user_commands (void)
 {
-  int i;
+  size_t i;
   for (i = 0; i < user_defined_number; i++)
     free (user_defined_command_data[i].cmdname);
   user_defined_number = 0;
diff --git a/tp/Texinfo/XS/parsetexi/def.c b/tp/Texinfo/XS/parsetexi/def.c
index 84b8caf790..fe74fba796 100644
--- a/tp/Texinfo/XS/parsetexi/def.c
+++ b/tp/Texinfo/XS/parsetexi/def.c
@@ -358,8 +358,8 @@ parse_def (enum command_id command, ELEMENT *current)
   size_t contents_idx = 0;
   int type, set_type_not_arg;
   size_t i;
-  int i_def;
-  int arg_types_nr;
+  size_t i_def;
+  size_t arg_types_nr;
   ELEMENT *e, *e1;
   enum element_type *arguments_types_list;
   int inserted_category = 0;
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c 
b/tp/Texinfo/XS/parsetexi/end_line.c
index 03ee0084cf..d3905c0241 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -681,7 +681,7 @@ end_line_def_line (ELEMENT *current)
   ELEMENT *def_info_name = 0;
   ELEMENT *def_info_class = 0;
   ELEMENT *def_info_category = 0;
-  int i = 0;
+  size_t i;
   enum context top_context = pop_context ();
 
   if (top_context != ct_def)
@@ -827,7 +827,10 @@ end_line_starting_block (ELEMENT *current)
     }
   else if (command == CM_multitable)
     {
-      int i;
+      size_t i;
+      /* NOTE max_columns could overflow, as in general max (int) < max 
(size_t).
+         We do not do anything special as this would be for unrealistically big
+         numbers for columns */
       int max_columns = 0;
 
       for (i = 0; i < current->e.c->contents.number; i++)
@@ -972,7 +975,7 @@ end_line_starting_block (ELEMENT *current)
          otherwise it is not a command_as_argument */
           if (k_command_as_arg)
             {
-              int i;
+              size_t i;
               ELEMENT *e = args_child_by_index (current, 0);
               ELEMENT *command_as_arg_e = k_command_as_arg->k.element;
 
@@ -1377,7 +1380,7 @@ end_line_misc_line (ELEMENT *current)
             }
           else if (current->e.c->cmd == CM_documentencoding)
             {
-              int i;
+              size_t i;
               char *normalized_text;
               int possible_encoding = 0;
 
@@ -1574,7 +1577,7 @@ end_line_misc_line (ELEMENT *current)
     }
   else if (current->e.c->cmd == CM_node)
     {
-      int i;
+      size_t i;
       ELEMENT *label_element;
 
       for (i = 1; i < current->e.c->args.number && i < 4; i++)
diff --git a/tp/Texinfo/XS/parsetexi/handle_commands.c 
b/tp/Texinfo/XS/parsetexi/handle_commands.c
index 5bc9ef323f..29f0bc4f25 100644
--- a/tp/Texinfo/XS/parsetexi/handle_commands.c
+++ b/tp/Texinfo/XS/parsetexi/handle_commands.c
@@ -69,7 +69,7 @@ int
 check_no_text (const ELEMENT *current)
 {
   int after_paragraph = 0;
-  int i, j;
+  size_t i, j;
   for (i = 0; i < current->e.c->contents.number; i++)
     {
       enum element_type t;
@@ -577,7 +577,7 @@ handle_line_command (ELEMENT *current, const char 
**line_inout,
       int has_comment = 0;
       int special_arg = 0;
       int ignored = 0;
-      int i;
+      size_t i;
 
       if (cmd == CM_insertcopying)
         {
@@ -679,7 +679,7 @@ handle_line_command (ELEMENT *current, const char 
**line_inout,
         }
       else if (!ignored)
         {
-          int i;
+          size_t i;
           size_t args_nr = args->number;
           command_e = new_command_element (ET_lineraw_command, cmd);
 
diff --git a/tp/Texinfo/XS/parsetexi/indices.c 
b/tp/Texinfo/XS/parsetexi/indices.c
index ea222cb9df..b3b60bf738 100644
--- a/tp/Texinfo/XS/parsetexi/indices.c
+++ b/tp/Texinfo/XS/parsetexi/indices.c
@@ -46,7 +46,7 @@
 #include "parser.h"
 #include "indices.h"
 
-int space_for_indices = 0;
+size_t space_for_indices = 0;
 
 typedef struct {
     enum command_id cmd;
@@ -77,7 +77,7 @@ associate_command_to_index (enum command_id cmd, INDEX *idx)
 INDEX *
 index_of_command (enum command_id cmd)
 {
-  int i;
+  size_t i;
 
   for (i = 0; i < num_index_commands; i++)
     {
@@ -161,7 +161,7 @@ init_index_commands (void)
     "tp", 1, CM_tpindex, CM_tindex, /* types */
     0, 0, 0, 0
   };
-  int i, j;
+  size_t i, j;
 
 #define MAX (10 * 2)
 
@@ -317,7 +317,7 @@ set_non_ignored_space_in_index_before_command (ELEMENT 
*content)
 {
   ELEMENT *e;
   ELEMENT *pending_spaces_element = 0;
-  int i;
+  size_t i;
   for (i = 0; i < content->e.c->contents.number; i++)
     {
       /* could also be, but it does not seems to be needed here:
@@ -385,7 +385,7 @@ complete_indices (DOCUMENT *document, int debug_level)
       INDEX *idx = indices->list[i];
       if (idx->entries_number > 0)
         {
-          int j;
+          size_t j;
           for (j = 0; j < idx->entries_number; j++)
             {
               INDEX_ENTRY *entry;
@@ -408,7 +408,7 @@ complete_indices (DOCUMENT *document, int debug_level)
                   ELEMENT *def_l_e = main_entry_element->e.c->args.list[0];
                   if (def_l_e->e.c->contents.number > 0)
                     {
-                      int ic;
+                      size_t ic;
                       for (ic = 0; ic < def_l_e->e.c->contents.number; ic++)
                         {
                           ELEMENT *arg = def_l_e->e.c->contents.list[ic];
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index ef8e7ffb0d..c99cac306e 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -55,7 +55,7 @@ COUNTER argument_brace_groups;
 MACRO *
 lookup_macro (enum command_id cmd)
 {
-  int i;
+  size_t i;
 
   for (i = 0; i < macro_number; i++)
     {
@@ -274,29 +274,29 @@ parse_macro_command_line (enum command_id cmd, const char 
**line_inout,
 
 /* Macro use. */
 
-/* Return index into given arguments to look for the value of NAME.
-   Return -1 if not found. */
+/* Return index +1 into given arguments to look for the value of NAME.
+   Return 0 if not found. */
 
-static int
+static size_t
 lookup_macro_parameter (const char *name, const ELEMENT *macro)
 {
-  int i, pos;
+  size_t i, idx;
   /* the args_list pointer is const not the ELEMENT */
   ELEMENT *const *args_list;
 
   /* Find 'arg' in MACRO parameters. */
   args_list = macro->e.c->args.list;
-  pos = 0;
+  idx = 0;
   for (i = 0; i < macro->e.c->args.number; i++)
     {
       if (args_list[i]->type == ET_macro_arg)
         {
           if (!strcmp (args_list[i]->e.text->text, name))
-            return pos;
-          pos++;
+            return idx +1;
+          idx++;
         }
     }
-  return -1;
+  return 0;
 }
 
 /* LINE points the opening brace in a macro invocation.  CMD is the command
@@ -310,7 +310,7 @@ expand_macro_arguments (const ELEMENT *macro, const char 
**line_inout,
   const char *pline = line;
   TEXT *arg;
   int braces_level = 1;
-  int args_total;
+  size_t args_total;
   int whitespaces_len;
   ELEMENT *argument = new_element (ET_brace_arg);
   ELEMENT *argument_content = new_text_element (ET_other_text);
@@ -319,6 +319,7 @@ expand_macro_arguments (const ELEMENT *macro, const char 
**line_inout,
   add_to_element_contents (argument, argument_content);
   arg = argument_content->e.text;
 
+  /* -1 because of the macro name */
   args_total = macro->e.c->args.number - 1;
 
   /* *pline is '{', advance past the open brace, start at braces_level = 1 */
@@ -452,9 +453,9 @@ expand_linemacro_arguments (const ELEMENT *macro, const 
char **line_inout,
   const char *pline = line;
   TEXT *arg;
   int braces_level = 0;
-  int args_total;
+  size_t args_total;
   int spaces_nr;
-  int i;
+  size_t i;
   ELEMENT *argument = new_element (ET_line_arg);
   ELEMENT *argument_content = new_text_element (ET_other_text);
 
@@ -474,6 +475,7 @@ expand_linemacro_arguments (const ELEMENT *macro, const 
char **line_inout,
       pline += spaces_nr;
     }
 
+  /* -1 because of the macro name */
   args_total = macro->e.c->args.number - 1;
 
   while (1)
@@ -642,7 +644,7 @@ static void
 expand_macro_body (const MACRO *macro_record, const ELEMENT *arguments,
                    TEXT *expanded)
 {
-  int pos; /* Index into arguments. */
+  size_t pos; /* Position, Index +1 into arguments. */
   const ELEMENT *macro;
   const char *macrobody;
   const char *ptext;
@@ -686,7 +688,7 @@ expand_macro_body (const MACRO *macro_record, const ELEMENT 
*arguments,
 
           name = strndup (ptext, bs - ptext);
           pos = lookup_macro_parameter (name, macro);
-          if (pos == -1)
+          if (pos == 0)
             {
               line_error ("\\ in @%s expansion followed `%s' instead of "
                           "parameter name or \\",
@@ -696,14 +698,15 @@ expand_macro_body (const MACRO *macro_record, const 
ELEMENT *arguments,
             }
           else
             {
-              if (arguments && pos < arguments->e.c->args.number)
+              size_t index = pos -1;
+              if (arguments && index < arguments->e.c->args.number)
                 {
                   const ELEMENT *argument
-                    = args_child_by_index (arguments, pos);
+                    = args_child_by_index (arguments, index);
                   if (argument->e.c->contents.number > 0)
                     text_append (expanded,
                       last_contents_child (
-                        args_child_by_index (arguments, pos))->e.text->text);
+                        args_child_by_index (arguments, index))->e.text->text);
                 }
             }
           free (name);
@@ -748,7 +751,7 @@ delete_macro (const char *name)
 void
 wipe_macros (void)
 {
-  int i;
+  size_t i;
 
   for (i = 0; i < macro_number; i++)
     {
@@ -770,7 +773,7 @@ handle_macro (ELEMENT *current, const char **line_inout, 
enum command_id cmd)
   const ELEMENT *macro;
   TEXT expanded;
   char *expanded_macro_text;
-  int args_number;
+  size_t args_number;
   SOURCE_MARK *macro_source_mark;
   ELEMENT *macro_call_element;
   int error = 0;
@@ -1003,7 +1006,7 @@ init_values (void)
 void
 store_value (VALUE_LIST *values, const char *name, const char *value)
 {
-  int i;
+  size_t i;
   VALUE *v = 0;
   int len;
 
@@ -1063,7 +1066,7 @@ store_parser_value (const char *name, const char *value)
 void
 clear_value (const char *name)
 {
-  int i;
+  size_t i;
   VALUE_LIST *values = &parser_values;
   for (i = 0; i < values->number; i++)
     {
@@ -1095,7 +1098,7 @@ clear_value (const char *name)
 char *
 fetch_value (const char *name)
 {
-  int i;
+  size_t i;
   VALUE_LIST *values = &parser_values;
   for (i = 0; i < values->number; i++)
     {
@@ -1115,7 +1118,7 @@ static size_t infoencl_space;
 INFO_ENCLOSE *
 lookup_infoenclose (enum command_id cmd)
 {
-  int i;
+  size_t i;
   for (i = 0; i < infoencl_number; i++)
     {
       if (infoencl_list[i].cmd == cmd)
@@ -1127,7 +1130,7 @@ lookup_infoenclose (enum command_id cmd)
 void
 add_infoenclose (enum command_id cmd, const char *begin, const char *end)
 {
-  int i;
+  size_t i;
   INFO_ENCLOSE *ie = 0;
 
   /* Check if already defined. */
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index cf61ef1536..f22fced747 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -41,7 +41,7 @@
 ELEMENT *
 register_extra_menu_entry_information (ELEMENT *current)
 {
-  int i;
+  size_t i;
   ELEMENT *menu_entry_node = 0;
 
   for (i = 0; i < current->e.c->contents.number; i++)
@@ -392,7 +392,7 @@ end_line_menu_entry (ELEMENT *current)
           debug ("THEN MENU_COMMENT OPEN");
         }
       {
-      int i, j;
+      size_t i, j;
       for (i = 0; i < menu_entry->e.c->contents.number; i++)
         {
           ELEMENT *arg = contents_child_by_index (menu_entry, i);
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index b2bd9101fa..b1ec5722c4 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -200,7 +200,8 @@ text_contents_to_plain_text (ELEMENT *e, int 
*superfluous_arg)
 {
 #define ADD(x,n) text_append_n (&result, x, n)
 
-  TEXT result; int i;
+  TEXT result;
+  size_t i;
 
   text_init (&result);
   for (i = 0; i < e->e.c->contents.number; i++)
@@ -755,7 +756,7 @@ do_abort_empty_line (ELEMENT *current, ELEMENT *last_elt)
         {
           SOURCE_MARK_LIST *source_mark_list = e->source_mark_list;
 
-          int i;
+          size_t i;
           for (i = 0; i < source_mark_list->number; i++)
             place_source_mark (current, source_mark_list->list[i]);
           free_element_source_mark_list (e);
@@ -786,7 +787,7 @@ ELEMENT *
 merge_text (ELEMENT *current, const char *text, size_t len_text,
             ELEMENT *transfer_marks_element)
 {
-  int leading_spaces = 0;
+  size_t leading_spaces = 0;
   ELEMENT *e;
   ELEMENT *last_element = last_contents_child (current);
 
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 0d821daa67..338ec9da07 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -262,7 +262,7 @@ handle_open_brace (ELEMENT *current, const char 
**line_inout)
 int
 check_empty_expansion (ELEMENT *e)
 {
-  int i;
+  size_t i;
   for (i = 0; i < e->e.c->contents.number; i++)
     {
       ELEMENT *f = e->e.c->contents.list[i];



reply via email to

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