texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/parsetexi/macro.c (expand_macro_a


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): fix arg_space, which is not the number of allocated elements in arg_list, but comparable to arg_number, with 1 added to obtain the allocated number of elements to add the null delimiter. Change name of new_arg_space to new_alloc_space to make clearer that it is the allocated number of elements, not a space comparable to arg_number.
Date: Sun, 05 Feb 2023 20:03:21 -0500

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new e0257c6d1c * tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): 
fix arg_space, which is not the number of allocated elements in arg_list, but 
comparable to arg_number, with 1 added to obtain the allocated number of 
elements to add the null delimiter.  Change name of new_arg_space to 
new_alloc_space to make clearer that it is the allocated number of elements, 
not a space comparable to arg_number.
e0257c6d1c is described below

commit e0257c6d1cf6ac468d98ac032773670a5fd60d81
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Feb 6 02:03:11 2023 +0100

    * tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): fix
    arg_space, which is not the number of allocated elements in arg_list,
    but comparable to arg_number, with 1 added to obtain the allocated
    number of elements to add the null delimiter.  Change name of
    new_arg_space to new_alloc_space to make clearer that it is the
    allocated number of elements, not a space comparable to arg_number.
---
 ChangeLog                       |  9 +++++++++
 tp/Texinfo/XS/parsetexi/macro.c | 22 ++++++++++++----------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5b66a01296..30982ff9aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-02-05  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): fix
+       arg_space, which is not the number of allocated elements in arg_list,
+       but comparable to arg_number, with 1 added to obtain the allocated
+       number of elements to add the null delimiter.  Change name of
+       new_arg_space to new_alloc_space to make clearer that it is the
+       allocated number of elements, not a space comparable to arg_number.
+
 2023-02-05  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/macro.c (expand_macro_arguments): always
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 8d49c7d2dc..5147bdd31b 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -251,11 +251,13 @@ expand_macro_arguments (ELEMENT *macro, char 
**line_inout, enum command_id cmd)
 
   char **arg_list = 0;
   size_t arg_number = 0;
-  size_t arg_space = 2;
+  /* arg_space is set to be comparable to arg_number, so need to allocate
+     1 more for the null delimiter */
+  /* start with an argument, which can be an empty string */
+  size_t arg_space = 1;
 
-  /* minimum 2 element in arg_list, an argument, which can be an empty string 
and
-     the null delimiter */
-  arg_list = malloc (sizeof (char *) * 2);
+  /* allocate 1 more for the null delimiter */
+  arg_list = malloc (sizeof (char *) * (arg_space + 1));
   args_total = macro->args.number - 1;
 
   text_init (&arg);
@@ -327,18 +329,18 @@ expand_macro_arguments (ELEMENT *macro, char 
**line_inout, enum command_id cmd)
               /* Add the last argument read to the list. */
               if (arg_number == arg_space)
                 {
-                  /* note that if args_total is 0, new_arg_space will be 1
+                  /* note that if args_total is 0, new_alloc_space will be 1
                      which is not enough for the minimum of an argument and
                      the terminating null element.  However, it is not possible
                      to have arg_number == arg_space in that case, as arg_space
-                     is minimum 2 and arg_number is maximum 0 if args_total is 
0 */
+                     is minimum 1 and arg_number is maximum 0 if args_total is 
0 */
                   /* Include space for terminating null element. */
-                  size_t new_arg_space = args_total + 1;
+                  size_t new_alloc_space = args_total + 1;
                   /* unless at the end, only allocate next 5 args */
-                  if (1 + arg_space + 5 < new_arg_space)
-                    new_arg_space = 1 + (arg_space += 5);
+                  if (1 + arg_space + 5 < new_alloc_space)
+                    new_alloc_space = 1 + (arg_space += 5);
                   arg_list = realloc (arg_list,
-                                      new_arg_space * sizeof (char *));
+                                      new_alloc_space * sizeof (char *));
                   if (!arg_list)
                     fatal ("realloc failed");
                 }



reply via email to

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