bug-gnulib
[Top][All Lists]
Advanced

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

regex backward search broken


From: Todd Lewis
Subject: regex backward search broken
Date: Fri, 5 Aug 2016 15:29:16 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

When using the regex code with _REGEX_LARGE_OFFSETS defined, backward
searches (where range<0) fail.

The diff below works around the problem, at least for re_search(), which
is the only regex function I'm using. The problem seems to be mixing
signed math -- 'range' is negative for backward searches -- with unsigned
"Idx"-typed variables 'length' and 'start'. "Idx" is an unsigned type when
_REGEX_LARGE_OFFSETS is defined. Behold:

-----------------------------------------
$ git diff --no-color regexec.c
diff --git a/src/regexec.c b/src/regexec.c
index 85de71d..ca10fea 100644
--- a/src/regexec.c
+++ b/src/regexec.c
@@ -410,8 +410,8 @@ re_search_2_stub (struct re_pattern_buffer *bufp,

 static regoff_t
 re_search_stub (struct re_pattern_buffer *bufp,
-               const char *string, Idx length,
-               Idx start, regoff_t range, Idx stop, struct re_registers
*regs,
+               const char *string, Idx ulength,
+               Idx ustart, regoff_t range, Idx stop, struct re_registers
*regs,
                bool ret_len)
 {
   reg_errcode_t result;
@@ -420,7 +420,9 @@ re_search_stub (struct re_pattern_buffer *bufp,
   regoff_t rval;
   int eflags = 0;
   re_dfa_t *dfa = bufp->buffer;
-  Idx last_start = start + range;
+  regoff_t start = ustart;
+  regoff_t length = ulength;
+  regoff_t last_start = start + range;

   /* Check for out-of-range.  */
   if (BE (start < 0 || start > length, 0))
-----------------------------------------


-- 
   +--------------------------------------------------------------+
  / address@hidden  919-445-0091  http://www.unc.edu/~utoddl /
 /   I just got lost in thought. It was unfamiliar territory.   /
+--------------------------------------------------------------+



reply via email to

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