[latex3-commits] [git/LaTeX3-latex3-latex3] main: Avoid using an inappropriate clist mapping in l3regex (c30190f64)

Bruno Le Floch blflatex at gmail.com
Sun May 16 12:20:20 CEST 2021


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/c30190f64cb7543901fbbefc11e7a8c78560b03b

>---------------------------------------------------------------

commit c30190f64cb7543901fbbefc11e7a8c78560b03b
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Sun May 16 12:20:20 2021 +0200

    Avoid using an inappropriate clist mapping in l3regex
    
    It was applied to a token list ending with a comma, which led to an
    extra iteration.  The extra iteration turned out to fill data beyond
    what was later read, but it is a bug waiting to happen.


>---------------------------------------------------------------

c30190f64cb7543901fbbefc11e7a8c78560b03b
 l3kernel/l3regex.dtx | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index f10b2f320..eb729b94a 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -6709,7 +6709,7 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\@@_extract:}
+% \begin{macro}{\@@_extract:, \@@_extract_aux:w}
 %   Our task here is to store the list of end-points of submatches, and
 %   store them in appropriate array entries, from
 %   \cs{l_@@_zeroth_submatch_int} upwards.  First, we store in
@@ -6732,18 +6732,23 @@
       \__kernel_intarray_gset:Nnn \g_@@_submatch_prev_intarray
         { \l_@@_zeroth_submatch_int } { \l_@@_start_pos_int }
       \int_zero:N \l_@@_internal_a_int
-      \clist_map_inline:Nn \l_@@_success_submatches_tl
-        {
-          \if_int_compare:w \l_@@_internal_a_int < \l_@@_capturing_group_int
-            \__kernel_intarray_gset:Nnn \g_@@_submatch_begin_intarray
-              { \@@_int_eval:w \l_@@_zeroth_submatch_int + \l_@@_internal_a_int } {##1}
-          \else:
-            \__kernel_intarray_gset:Nnn \g_@@_submatch_end_intarray
-              { \@@_int_eval:w \l_@@_zeroth_submatch_int + \l_@@_internal_a_int - \l_@@_capturing_group_int } {##1}
-          \fi:
-          \int_incr:N \l_@@_internal_a_int
-        }
+      \exp_after:wN \@@_extract_aux:w \l_@@_success_submatches_tl
+        \prg_break_point: \@@_use_none_delimit_by_q_recursion_stop:w ,
+        \q_@@_recursion_stop
+    \fi:
+  }
+\cs_new_protected:Npn \@@_extract_aux:w #1 ,
+  {
+    \prg_break: #1 \prg_break_point:
+    \if_int_compare:w \l_@@_internal_a_int < \l_@@_capturing_group_int
+      \__kernel_intarray_gset:Nnn \g_@@_submatch_begin_intarray
+        { \@@_int_eval:w \l_@@_zeroth_submatch_int + \l_@@_internal_a_int } {#1}
+    \else:
+      \__kernel_intarray_gset:Nnn \g_@@_submatch_end_intarray
+        { \@@_int_eval:w \l_@@_zeroth_submatch_int + \l_@@_internal_a_int - \l_@@_capturing_group_int } {#1}
     \fi:
+    \int_incr:N \l_@@_internal_a_int
+    \@@_extract_aux:w
   }
 %    \end{macrocode}
 % \end{macro}





More information about the latex3-commits mailing list.