/[pcre]/code/trunk/pcre_exec.c
ViewVC logotype

Diff of /code/trunk/pcre_exec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 381 by ph10, Tue Mar 3 16:08:23 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2006 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45    #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49    #define NLBLOCK md             /* Block containing newline information */
50    #define PSSTART start_subject  /* Field containing processed string start */
51    #define PSEND   end_subject    /* Field containing processed string end */
52    
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    /* Undefine some potentially clashing cpp symbols */
56    
57  /* Structure for building a chain of data that actually lives on the  #undef min
58  stack, for holding the values of the subject pointer at the start of each  #undef max
 subpattern, so as to detect when an empty string has been matched by a  
 subpattern - to break infinite loops. When NO_RECURSE is set, these blocks  
 are on the heap, not on the stack. */  
   
 typedef struct eptrblock {  
   struct eptrblock *epb_prev;  
   USPTR epb_saved_eptr;  
 } eptrblock;  
59    
60  /* Flag bits for the match() function */  /* Flag bits for the match() function */
61    
62  #define match_condassert   0x01    /* Called to check a condition assertion */  #define match_condassert     0x01  /* Called to check a condition assertion */
63  #define match_isgroup      0x02    /* Set if start of bracketed group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
64    
65  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
66  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 68  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
80  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 101  Returns:     nothing Line 109  Returns:     nothing
109  static void  static void
110  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
111  {  {
112  int c;  unsigned int c;
113  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
114  while (length-- > 0)  while (length-- > 0)
115    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
# Line 150  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 186  calls by keeping local variables that ne Line 220  calls by keeping local variables that ne
220  obtained from malloc() instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
221  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
222  always used to.  always used to.
223    
224    The original heap-recursive code used longjmp(). However, it seems that this
225    can be very slow on some operating systems. Following a suggestion from Stan
226    Switzer, the use of longjmp() has been abolished, at the cost of having to
227    provide a unique number for each call to RMATCH. There is no way of generating
228    a sequence of numbers at compile time in C. I have given them names, to make
229    them stand out more clearly.
230    
231    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
232    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
233    tests. Furthermore, not using longjmp() means that local dynamic variables
234    don't have indeterminate values; this has meant that the frame size can be
235    reduced because the result can be "passed back" by straight setting of the
236    variable instead of being passed in the frame.
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241    below must be updated in sync.  */
242    
243    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
251  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
252    actuall used in this definition. */
253    
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256    
257  #ifdef DEBUG  #ifdef DEBUG
258  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
261    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 267  versions and production versions. */
267    return ra; \    return ra; \
268    }    }
269  #else  #else
270  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273  #endif  #endif
274    
275  #else  #else
276    
277    
278  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
279  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
280  match(), which never changes. */  argument of match(), which never changes. */
281    
282  #define REGISTER  #define REGISTER
283    
284  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
285    {\    {\
286    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
287    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
288      {\    newframe->Xeptr = ra;\
289      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
290      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
291      newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
292      newframe->Xims = re;\    newframe->Xims = re;\
293      newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
294      newframe->Xflags = rg;\    newframe->Xflags = rg;\
295      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
297      frame = newframe;\    frame = newframe;\
298      DPRINTF(("restarting from line %d\n", __LINE__));\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      goto HEAP_RECURSE;\    goto HEAP_RECURSE;\
300      }\    L_##rw:\
301    else\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     {\  
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
302    }    }
303    
304  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 254  match(), which never changes. */ Line 308  match(), which never changes. */
308    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
309    if (frame != NULL)\    if (frame != NULL)\
310      {\      {\
311      frame->Xresult = ra;\      rrc = ra;\
312      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
313      }\      }\
314    return ra;\    return ra;\
315    }    }
# Line 271  typedef struct heapframe { Line 324  typedef struct heapframe {
324    
325    const uschar *Xeptr;    const uschar *Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      const uschar *Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
331    int Xflags;    int Xflags;
332    int Xrdepth;    unsigned int Xrdepth;
333    
334    /* Function local variables */    /* Function local variables */
335    
# Line 291  typedef struct heapframe { Line 345  typedef struct heapframe {
345    
346    BOOL Xcur_is_word;    BOOL Xcur_is_word;
347    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
348    BOOL Xprev_is_word;    BOOL Xprev_is_word;
349    
350    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 356  typedef struct heapframe {
356    int Xprop_category;    int Xprop_category;
357    int Xprop_chartype;    int Xprop_chartype;
358    int Xprop_script;    int Xprop_script;
359    int *Xprop_test_variable;    int Xoclength;
360      uschar Xocchars[8];
361  #endif  #endif
362    
363    int Xctype;    int Xctype;
364    int Xfc;    unsigned int Xfc;
365    int Xfi;    int Xfi;
366    int Xlength;    int Xlength;
367    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 375  typedef struct heapframe {
375    
376    eptrblock Xnewptrb;    eptrblock Xnewptrb;
377    
378    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
379    
380    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
381    
382  } heapframe;  } heapframe;
383    
# Line 340  typedef struct heapframe { Line 393  typedef struct heapframe {
393  *         Match from current position            *  *         Match from current position            *
394  *************************************************/  *************************************************/
395    
396  /* On entry ecode points to the first opcode, and eptr to the first character  /* This function is called recursively in many circumstances. Whenever it
 in the subject string, while eptrb holds the value of eptr at the start of the  
 last bracketed group - used for breaking infinite loops matching zero-length  
 strings. This function is called recursively in many circumstances. Whenever it  
397  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
398  same response.  same response.
399    
# Line 353  performance. Tests using gcc on a SPARC Line 403  performance. Tests using gcc on a SPARC
403  made performance worse.  made performance worse.
404    
405  Arguments:  Arguments:
406     eptr        pointer in subject     eptr        pointer to current character in subject
407     ecode       position in code     ecode       pointer to current position in compiled code
408       mstart      pointer to the current match start position (can be modified
409                     by encountering \K)
410     offset_top  current top pointer     offset_top  current top pointer
411     md          pointer to "static" info for the match     md          pointer to "static" info for the match
412     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 414  Arguments:
414                   brackets - for testing for empty matches                   brackets - for testing for empty matches
415     flags       can contain     flags       can contain
416                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
417                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
418                       group that can match an empty string
419     rdepth      the recursion depth     rdepth      the recursion depth
420    
421  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 372  Returns:       MATCH_MATCH if matched Line 425  Returns:       MATCH_MATCH if matched
425  */  */
426    
427  static int  static int
428  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,
429    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
430    int flags, int rdepth)    int flags, unsigned int rdepth)
431  {  {
432  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
433  so they can be ordinary variables in all cases. Mark them with "register"  so they can be ordinary variables in all cases. Mark some of them with
434  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
435    
436  register int  rrc;    /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
437  register int  i;      /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
438  register int  c;      /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
439  register BOOL utf8;   /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
440    
441    BOOL minimize, possessive; /* Quantifier options */
442    
443  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
444  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
# Line 398  frame->Xprevframe = NULL;            /* Line 453  frame->Xprevframe = NULL;            /*
453    
454  frame->Xeptr = eptr;  frame->Xeptr = eptr;
455  frame->Xecode = ecode;  frame->Xecode = ecode;
456    frame->Xmstart = mstart;
457  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
458  frame->Xims = ims;  frame->Xims = ims;
459  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 468  HEAP_RECURSE:
468    
469  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
470  #define ecode              frame->Xecode  #define ecode              frame->Xecode
471    #define mstart             frame->Xmstart
472  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
473  #define ims                frame->Xims  #define ims                frame->Xims
474  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 434  HEAP_RECURSE: Line 491  HEAP_RECURSE:
491    
492  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
493  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
494  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
495    
496  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 502  HEAP_RECURSE:
502  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
503  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
504  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
505  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
506    #define occhars            frame->Xocchars
507  #endif  #endif
508    
509  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 527  HEAP_RECURSE:
527  get preserved during recursion in the normal way. In this environment, fi and  get preserved during recursion in the normal way. In this environment, fi and
528  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
529    
530  #else  #else         /* NO_RECURSE not defined */
531  #define fi i  #define fi i
532  #define fc c  #define fc c
533    
# Line 489  recursion_info new_recursive;      /* wi Line 546  recursion_info new_recursive;      /* wi
546                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
547  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
548  BOOL condition;  BOOL condition;
 BOOL minimize;  
549  BOOL prev_is_word;  BOOL prev_is_word;
550    
551  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 557  int prop_fail_result;
557  int prop_category;  int prop_category;
558  int prop_chartype;  int prop_chartype;
559  int prop_script;  int prop_script;
560  int *prop_test_variable;  int oclength;
561    uschar occhars[8];
562  #endif  #endif
563    
564  int ctype;  int ctype;
# Line 516  int save_offset1, save_offset2, save_off Line 573  int save_offset1, save_offset2, save_off
573  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
574    
575  eptrblock newptrb;  eptrblock newptrb;
576  #endif  #endif     /* NO_RECURSE */
577    
578  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
579  variables. */  variables. */
# Line 524  variables. */ Line 581  variables. */
581  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
582  prop_value = 0;  prop_value = 0;
583  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
584  #endif  #endif
585    
586    
587    /* This label is used for tail recursion, which is used in a few cases even
588    when NO_RECURSE is not defined, in order to reduce the amount of stack that is
589    used. Thanks to Ian Taylor for noticing this possibility and sending the
590    original patch. */
591    
592    TAIL_RECURSE:
593    
594  /* OK, now we can get on with the real code of the function. Recursive calls  /* OK, now we can get on with the real code of the function. Recursive calls
595  are specified by the macro RMATCH and RRETURN is used to return. When  are specified by the macro RMATCH and RRETURN is used to return. When
596  NO_RECURSE is *not* defined, these just turn into a recursive call to match()  NO_RECURSE is *not* defined, these just turn into a recursive call to match()
# Line 535  defined). However, RMATCH isn't like a f Line 599  defined). However, RMATCH isn't like a f
599  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
600  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
601    
602    #ifdef SUPPORT_UTF8
603    utf8 = md->utf8;       /* Local copy of the flag */
604    #else
605    utf8 = FALSE;
606    #endif
607    
608  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
609  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
610    
# Line 542  if (md->match_call_count++ >= md->match_ Line 612  if (md->match_call_count++ >= md->match_
612  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
613    
614  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
 utf8 = md->utf8;       /* Local copy of the flag */  
615    
616  /* At the start of a bracketed group, add the current subject pointer to the  /* At the start of a group with an unlimited repeat that may match an empty
617  stack of such pointers, to be re-instated at the end of the group when we hit  string, the match_cbegroup flag is set. When this is the case, add the current
618  the closing ket. When match() is called in other circumstances, we don't add to  subject pointer to the chain of such remembered pointers, to be checked when we
619  this stack. */  hit the closing ket, in order to break infinite loops that match no characters.
620    When match() is called in other circumstances, don't add to the chain. The
621    match_cbegroup flag must NOT be used with tail recursion, because the memory
622    block that is used is on the stack, so a new one may be required for each
623    match(). */
624    
625  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
626    {    {
   newptrb.epb_prev = eptrb;  
627    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
628      newptrb.epb_prev = eptrb;
629    eptrb = &newptrb;    eptrb = &newptrb;
630    }    }
631    
632  /* Now start processing the operations. */  /* Now start processing the opcodes. */
633    
634  for (;;)  for (;;)
635    {    {
636      minimize = possessive = FALSE;
637    op = *ecode;    op = *ecode;
   minimize = FALSE;  
638    
639    /* For partial matching, remember if we ever hit the end of the subject after    /* For partial matching, remember if we ever hit the end of the subject after
640    matching at least one subject character. */    matching at least one subject character. */
641    
642    if (md->partial &&    if (md->partial &&
643        eptr >= md->end_subject &&        eptr >= md->end_subject &&
644        eptr > md->start_match)        eptr > mstart)
645      md->hitend = TRUE;      md->hitend = TRUE;
646    
647    /* Opening capturing bracket. If there is space in the offset vector, save    switch(op)
   the current subject position in the working slot at the top of the vector. We  
   mustn't change the current values of the data slot, because they may be set  
   from a previous iteration of this group, and be referred to by a reference  
   inside the group.  
   
   If the bracket fails to match, we need to restore this value and also the  
   values of the final offsets, in case they were set by a previous iteration of  
   the same bracket.  
   
   If there isn't enough space in the offset vector, treat this as if it were a  
   non-capturing bracket. Don't worry about setting the flag for the error case  
   here; that is handled in the code for KET. */  
   
   if (op > OP_BRA)  
648      {      {
649      number = op - OP_BRA;      case OP_FAIL:
650        RRETURN(MATCH_NOMATCH);
     /* For extended extraction brackets (large number), we have to fish out the  
     number from a dummy opcode at the start. */  
651    
652      if (number > EXTRACT_BASIC_MAX)      case OP_PRUNE:
653        number = GET2(ecode, 2+LINK_SIZE);      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
654          ims, eptrb, flags, RM51);
655        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
656        RRETURN(MATCH_PRUNE);
657    
658        case OP_COMMIT:
659        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
660          ims, eptrb, flags, RM52);
661        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
662        RRETURN(MATCH_COMMIT);
663    
664        case OP_SKIP:
665        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
666          ims, eptrb, flags, RM53);
667        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
668        md->start_match_ptr = eptr;   /* Pass back current position */
669        RRETURN(MATCH_SKIP);
670    
671        case OP_THEN:
672        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
673          ims, eptrb, flags, RM54);
674        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
675        RRETURN(MATCH_THEN);
676    
677        /* Handle a capturing bracket. If there is space in the offset vector, save
678        the current subject position in the working slot at the top of the vector.
679        We mustn't change the current values of the data slot, because they may be
680        set from a previous iteration of this group, and be referred to by a
681        reference inside the group.
682    
683        If the bracket fails to match, we need to restore this value and also the
684        values of the final offsets, in case they were set by a previous iteration
685        of the same bracket.
686    
687        If there isn't enough space in the offset vector, treat this as if it were
688        a non-capturing bracket. Don't worry about setting the flag for the error
689        case here; that is handled in the code for KET. */
690    
691        case OP_CBRA:
692        case OP_SCBRA:
693        number = GET2(ecode, 1+LINK_SIZE);
694      offset = number << 1;      offset = number << 1;
695    
696  #ifdef DEBUG  #ifdef DEBUG
697      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
698        printf("subject=");
699      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
700      printf("\n");      printf("\n");
701  #endif  #endif
# Line 612  for (;;) Line 710  for (;;)
710        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
711        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
712    
713          flags = (op == OP_SCBRA)? match_cbegroup : 0;
714        do        do
715          {          {
716          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
717            match_isgroup);            ims, eptrb, flags, RM1);
718          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
719          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
720          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
721          }          }
# Line 631  for (;;) Line 730  for (;;)
730        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
731        }        }
732    
733      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
734        as a non-capturing bracket. */
735    
736      else op = OP_BRA;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
737      }      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
738    
739    /* Other types of node can be handled by a switch */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
740    
741    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
742      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
743      case OP_BRA:     /* Non-capturing bracket: optimized */  
744      DPRINTF(("start bracket 0\n"));      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
745      do      final alternative within the brackets, we would return the result of a
746        recursive call to match() whatever happened. We can reduce stack usage by
747        turning this into a tail recursion, except in the case when match_cbegroup
748        is set.*/
749    
750        case OP_BRA:
751        case OP_SBRA:
752        DPRINTF(("start non-capturing bracket\n"));
753        flags = (op >= OP_SBRA)? match_cbegroup : 0;
754        for (;;)
755        {        {
756        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
757          match_isgroup);          {
758        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (flags == 0)    /* Not a possibly empty group */
759              {
760              ecode += _pcre_OP_lengths[*ecode];
761              DPRINTF(("bracket 0 tail recursion\n"));
762              goto TAIL_RECURSE;
763              }
764    
765            /* Possibly empty group; can't use tail recursion. */
766    
767            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
768              eptrb, flags, RM48);
769            RRETURN(rrc);
770            }
771    
772          /* For non-final alternatives, continue the loop for a NOMATCH result;
773          otherwise return. */
774    
775          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
776            eptrb, flags, RM2);
777          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
778        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
779        }        }
780      while (*ecode == OP_ALT);      /* Control never reaches here. */
     DPRINTF(("bracket 0 failed\n"));  
     RRETURN(MATCH_NOMATCH);  
781    
782      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
783      two branches. If the condition is false, skipping the first branch takes us      two branches. If the condition is false, skipping the first branch takes us
784      past the end if there is only one branch, but that's OK because that is      past the end if there is only one branch, but that's OK because that is
785      exactly what going to the ket would do. */      exactly what going to the ket would do. As there is only one branch to be
786        obeyed, we can use tail recursion to avoid using another stack frame. */
787    
788      case OP_COND:      case OP_COND:
789      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
790        /* Because of the way auto-callout works during compile, a callout item is
791        inserted between OP_COND and an assertion condition. */
792    
793        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
794          {
795          if (pcre_callout != NULL)
796            {
797            pcre_callout_block cb;
798            cb.version          = 1;   /* Version 1 of the callout block */
799            cb.callout_number   = ecode[LINK_SIZE+2];
800            cb.offset_vector    = md->offset_vector;
801            cb.subject          = (PCRE_SPTR)md->start_subject;
802            cb.subject_length   = md->end_subject - md->start_subject;
803            cb.start_match      = mstart - md->start_subject;
804            cb.current_position = eptr - md->start_subject;
805            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
806            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
807            cb.capture_top      = offset_top/2;
808            cb.capture_last     = md->capture_last;
809            cb.callout_data     = md->callout_data;
810            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
811            if (rrc < 0) RRETURN(rrc);
812            }
813          ecode += _pcre_OP_lengths[OP_CALLOUT];
814          }
815    
816        /* Now see what the actual condition is */
817    
818        if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */
819          {
820          offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
821          condition = md->recursive != NULL &&
822            (offset == RREF_ANY || offset == md->recursive->group_num);
823          ecode += condition? 3 : GET(ecode, 1);
824          }
825    
826        else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */
827        {        {
828        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
829        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
830          (md->recursive != NULL) :        ecode += condition? 3 : GET(ecode, 1);
831          (offset < offset_top && md->offset_vector[offset] >= 0);        }
832        RMATCH(rrc, eptr, ecode + (condition?  
833          (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))),      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */
834          offset_top, md, ims, eptrb, match_isgroup);        {
835        RRETURN(rrc);        condition = FALSE;
836          ecode += GET(ecode, 1);
837        }        }
838    
839      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
840      the final argument TRUE causes it to stop at the end of an assertion. */      the final argument match_condassert causes it to stop at the end of an
841        assertion. */
842    
843      else      else
844        {        {
845        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
846            match_condassert | match_isgroup);            match_condassert, RM3);
847        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
848          {          {
849          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
850            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
851          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
852          }          }
853        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
854          {          {
855          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
856          }          }
857        else ecode += GET(ecode, 1);        else
858        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          {
859          match_isgroup);          condition = FALSE;
860        RRETURN(rrc);          ecode += GET(ecode, 1);
861            }
862        }        }
     /* Control never reaches here */  
863    
864      /* Skip over conditional reference or large extraction number data if      /* We are now at the branch that is to be obeyed. As there is only one,
865      encountered. */      we can use tail recursion to avoid using another stack frame, except when
866        match_cbegroup is required for an unlimited repeat of a possibly empty
867        group. If the second alternative doesn't exist, we can just plough on. */
868    
869      case OP_CREF:      if (condition || *ecode == OP_ALT)
870      case OP_BRANUMBER:        {
871      ecode += 3;        ecode += 1 + LINK_SIZE;
872          if (op == OP_SCOND)        /* Possibly empty group */
873            {
874            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
875            RRETURN(rrc);
876            }
877          else                       /* Group must match something */
878            {
879            flags = 0;
880            goto TAIL_RECURSE;
881            }
882          }
883        else                         /* Condition false & no 2nd alternative */
884          {
885          ecode += 1 + LINK_SIZE;
886          }
887      break;      break;
888    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
889    
890        /* End of the pattern, either real or forced. If we are in a top-level
891        recursion, we should restore the offsets appropriately and continue from
892        after the call. */
893    
894        case OP_ACCEPT:
895      case OP_END:      case OP_END:
896      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
897        {        {
# Line 713  for (;;) Line 900  for (;;)
900        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
901        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
902          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
903        md->start_match = rec->save_start;        mstart = rec->save_start;
904        ims = original_ims;        ims = original_ims;
905        ecode = rec->after_call;        ecode = rec->after_call;
906        break;        break;
# Line 722  for (;;) Line 909  for (;;)
909      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
910      string - backtracking will then try other alternatives, if any. */      string - backtracking will then try other alternatives, if any. */
911    
912      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
913      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
914      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
915        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
916      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
917    
918      /* Change option settings */      /* Change option settings */
# Line 745  for (;;) Line 933  for (;;)
933      case OP_ASSERTBACK:      case OP_ASSERTBACK:
934      do      do
935        {        {
936        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
937          match_isgroup);          RM4);
938        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
939        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
940        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
941        }        }
942      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 772  for (;;) Line 960  for (;;)
960      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
961      do      do
962        {        {
963        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
964          match_isgroup);          RM5);
965        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
966        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
967        ecode += GET(ecode,1);        ecode += GET(ecode,1);
968        }        }
969      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 794  for (;;) Line 982  for (;;)
982  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
983      if (utf8)      if (utf8)
984        {        {
985        c = GET(ecode,1);        i = GET(ecode, 1);
986        for (i = 0; i < c; i++)        while (i-- > 0)
987          {          {
988          eptr--;          eptr--;
989          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
990          BACKCHAR(eptr)          BACKCHAR(eptr);
991          }          }
992        }        }
993      else      else
# Line 808  for (;;) Line 996  for (;;)
996      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
997    
998        {        {
999        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1000        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1001        }        }
1002    
# Line 830  for (;;) Line 1018  for (;;)
1018        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1019        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1020        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1021        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1022        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1023        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1024        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 865  for (;;) Line 1053  for (;;)
1053      case OP_RECURSE:      case OP_RECURSE:
1054        {        {
1055        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1056        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1057            GET2(callpat, 1 + LINK_SIZE);
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (new_recursive.group_num > EXTRACT_BASIC_MAX)  
         new_recursive.group_num = GET2(callpat, 2+LINK_SIZE);  
1058    
1059        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1060    
# Line 897  for (;;) Line 1080  for (;;)
1080    
1081        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1082              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1083        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1084        md->start_match = eptr;        mstart = eptr;
1085    
1086        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
1087        restore the offset and recursion data. */        restore the offset and recursion data. */
1088    
1089        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1090          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1091        do        do
1092          {          {
1093          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1094              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1095          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1096            {            {
1097            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 916  for (;;) Line 1100  for (;;)
1100              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1101            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1102            }            }
1103          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1104            {            {
1105            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1106            RRETURN(rrc);            RRETURN(rrc);
# Line 945  for (;;) Line 1129  for (;;)
1129      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer. */
1130    
1131      case OP_ONCE:      case OP_ONCE:
1132        {      prev = ecode;
1133        prev = ecode;      saved_eptr = eptr;
       saved_eptr = eptr;  
1134    
1135        do      do
1136          {        {
1137          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1138            eptrb, match_isgroup);        if (rrc == MATCH_MATCH) break;
1139          if (rrc == MATCH_MATCH) break;        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1140          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        ecode += GET(ecode,1);
1141          ecode += GET(ecode,1);        }
1142          }      while (*ecode == OP_ALT);
       while (*ecode == OP_ALT);  
1143    
1144        /* If hit the end of the group (which could be repeated), fail */      /* If hit the end of the group (which could be repeated), fail */
1145    
1146        if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1147    
1148        /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1149        mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1150    
1151        do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1152    
1153        offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1154        eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
1155    
1156        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1157        happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1158        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1159        5.005. If there is an options reset, it will get obeyed in the normal      5.005. If there is an options reset, it will get obeyed in the normal
1160        course of events. */      course of events. */
1161    
1162        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1163          {        {
1164          ecode += 1+LINK_SIZE;        ecode += 1+LINK_SIZE;
1165          break;        break;
1166          }        }
1167    
1168        /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1169        preceding bracket, in the appropriate order. We need to reset any options      preceding bracket, in the appropriate order. The second "call" of match()
1170        that changed within the bracket before re-running it, so check the next      uses tail recursion, to avoid using another stack frame. We need to reset
1171        opcode. */      any options that changed within the bracket before re-running it, so
1172        check the next opcode. */
1173    
1174        if (ecode[1+LINK_SIZE] == OP_OPT)      if (ecode[1+LINK_SIZE] == OP_OPT)
1175          {        {
1176          ims = (ims & ~PCRE_IMS) | ecode[4];        ims = (ims & ~PCRE_IMS) | ecode[4];
1177          DPRINTF(("ims set to %02lx at group repeat\n", ims));        DPRINTF(("ims set to %02lx at group repeat\n", ims));
1178          }        }
1179    
1180        if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1181          {        {
1182          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1183          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1184          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        ecode = prev;
1185          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        flags = 0;
1186          }        goto TAIL_RECURSE;
       else  /* OP_KETRMAX */  
         {  
         RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         }  
1187        }        }
1188      RRETURN(MATCH_NOMATCH);      else  /* OP_KETRMAX */
1189          {
1190          RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1191          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1192          ecode += 1 + LINK_SIZE;
1193          flags = 0;
1194          goto TAIL_RECURSE;
1195          }
1196        /* Control never gets here */
1197    
1198      /* An alternation is the end of a branch; scan along to find the end of the      /* An alternation is the end of a branch; scan along to find the end of the
1199      bracketed group and go to there. */      bracketed group and go to there. */
# Line 1018  for (;;) Line 1202  for (;;)
1202      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1203      break;      break;
1204    
1205      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1206      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1207      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1208      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1209      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1210    
1211      case OP_BRAZERO:      case OP_BRAZERO:
1212        {        {
1213        next = ecode+1;        next = ecode+1;
1214        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1215        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1216        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1217        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1218        }        }
1219      break;      break;
1220    
1221      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1222        {        {
1223        next = ecode+1;        next = ecode+1;
1224        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1225        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
         match_isgroup);  
1226        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1227        ecode++;        ecode++;
1228        }        }
1229      break;      break;
1230    
1231      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1232      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1233      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1234      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1235          ecode = next + 1 + LINK_SIZE;
1236          }
1237        break;
1238    
1239        /* End of a group, repeated or non-repeating. */
1240    
1241      case OP_KET:      case OP_KET:
1242      case OP_KETRMIN:      case OP_KETRMIN:
1243      case OP_KETRMAX:      case OP_KETRMAX:
1244        {      prev = ecode - GET(ecode, 1);
       prev = ecode - GET(ecode, 1);  
       saved_eptr = eptrb->epb_saved_eptr;  
1245    
1246        /* Back up the stack of bracket start pointers. */      /* If this was a group that remembered the subject start, in order to break
1247        infinite repeats of empty string matches, retrieve the subject start from
1248        the chain. Otherwise, set it NULL. */
1249    
1250        eptrb = eptrb->epb_prev;      if (*prev >= OP_SBRA)
1251          {
1252        if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1253            *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||        eptrb = eptrb->epb_prev;              /* Backup to previous group */
1254            *prev == OP_ONCE)        }
1255          {      else saved_eptr = NULL;
         md->end_match_ptr = eptr;      /* For ONCE */  
         md->end_offset_top = offset_top;  
         RRETURN(MATCH_MATCH);  
         }  
1256    
1257        /* In all other cases except a conditional group we have to check the      /* If we are at the end of an assertion group, stop matching and return
1258        group number back at the start and if necessary complete handling an      MATCH_MATCH, but record the current high water mark for use by positive
1259        extraction by setting the offsets and bumping the high water mark. */      assertions. Do this also for the "once" (atomic) groups. */
1260    
1261        if (*prev != OP_COND)      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1262          {          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1263          number = *prev - OP_BRA;          *prev == OP_ONCE)
1264          {
1265          md->end_match_ptr = eptr;      /* For ONCE */
1266          md->end_offset_top = offset_top;
1267          RRETURN(MATCH_MATCH);
1268          }
1269    
1270          /* For extended extraction brackets (large number), we have to fish out      /* For capturing groups we have to check the group number back at the start
1271          the number from a dummy opcode at the start. */      and if necessary complete handling an extraction by setting the offsets and
1272        bumping the high water mark. Note that whole-pattern recursion is coded as
1273        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1274        when the OP_END is reached. Other recursion is handled here. */
1275    
1276          if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1277          offset = number << 1;        {
1278          number = GET2(prev, 1+LINK_SIZE);
1279          offset = number << 1;
1280    
1281  #ifdef DEBUG  #ifdef DEBUG
1282          printf("end bracket %d", number);        printf("end bracket %d", number);
1283          printf("\n");        printf("\n");
1284  #endif  #endif
1285    
1286          /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1287          of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1288          into group 0, so it won't be picked up here. Instead, we catch it when          {
1289          the OP_END is reached. */          md->offset_vector[offset] =
1290              md->offset_vector[md->offset_end - number];
1291          if (number > 0)          md->offset_vector[offset+1] = eptr - md->start_subject;
1292            {          if (offset_top <= offset) offset_top = offset + 2;
1293            md->capture_last = number;          }
           if (offset >= md->offset_max) md->offset_overflow = TRUE; else  
             {  
             md->offset_vector[offset] =  
               md->offset_vector[md->offset_end - number];  
             md->offset_vector[offset+1] = eptr - md->start_subject;  
             if (offset_top <= offset) offset_top = offset + 2;  
             }  
1294    
1295            /* Handle a recursively called group. Restore the offsets        /* Handle a recursively called group. Restore the offsets
1296            appropriately and continue from after the call. */        appropriately and continue from after the call. */
1297    
1298            if (md->recursive != NULL && md->recursive->group_num == number)        if (md->recursive != NULL && md->recursive->group_num == number)
1299              {          {
1300              recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1301              DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1302              md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
1303              md->start_match = rec->save_start;          mstart = rec->save_start;
1304              memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1305                rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1306              ecode = rec->after_call;          ecode = rec->after_call;
1307              ims = original_ims;          ims = original_ims;
1308              break;          break;
             }  
           }  
1309          }          }
1310          }
1311    
1312        /* Reset the value of the ims flags, in case they got changed during      /* For both capturing and non-capturing groups, reset the value of the ims
1313        the group. */      flags, in case they got changed during the group. */
1314    
1315        ims = original_ims;      ims = original_ims;
1316        DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
1317    
1318        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1319        happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1320        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1321        5.005. If there is an options reset, it will get obeyed in the normal      5.005. If there is an options reset, it will get obeyed in the normal
1322        course of events. */      course of events. */
1323    
1324        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1325          {        {
1326          ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1327          break;        break;
1328          }        }
1329    
1330        /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1331        preceding bracket, in the appropriate order. */      preceding bracket, in the appropriate order. In the second case, we can use
1332        tail recursion to avoid using another stack frame, unless we have an
1333        unlimited repeat of a group that can match an empty string. */
1334    
1335        if (*ecode == OP_KETRMIN)      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1336          {  
1337          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);      if (*ecode == OP_KETRMIN)
1338          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        {
1339          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1340          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1341          }        if (flags != 0)    /* Could match an empty string */
       else  /* OP_KETRMAX */  
1342          {          {
1343          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1344          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          RRETURN(rrc);
         RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
1345          }          }
1346          ecode = prev;
1347          goto TAIL_RECURSE;
1348        }        }
1349        else  /* OP_KETRMAX */
1350      RRETURN(MATCH_NOMATCH);        {
1351          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1352          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1353          ecode += 1 + LINK_SIZE;
1354          flags = 0;
1355          goto TAIL_RECURSE;
1356          }
1357        /* Control never gets here */
1358    
1359      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1360    
# Line 1168  for (;;) Line 1362  for (;;)
1362      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1363      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1364        {        {
1365        if (eptr != md->start_subject && eptr[-1] != NEWLINE)        if (eptr != md->start_subject &&
1366              (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1367          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1368        ecode++;        ecode++;
1369        break;        break;
# Line 1189  for (;;) Line 1384  for (;;)
1384      ecode++;      ecode++;
1385      break;      break;
1386    
1387        /* Reset the start of match point */
1388    
1389        case OP_SET_SOM:
1390        mstart = eptr;
1391        ecode++;
1392        break;
1393    
1394      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1395      newline unless endonly is set, else end of subject unless noteol is set. */      newline unless endonly is set, else end of subject unless noteol is set. */
1396    
# Line 1196  for (;;) Line 1398  for (;;)
1398      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1399        {        {
1400        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1401          { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
1402        else        else
1403          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) RRETURN(MATCH_NOMATCH); }
1404        ecode++;        ecode++;
# Line 1207  for (;;) Line 1409  for (;;)
1409        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
1410        if (!md->endonly)        if (!md->endonly)
1411          {          {
1412          if (eptr < md->end_subject - 1 ||          if (eptr != md->end_subject &&
1413             (eptr == md->end_subject - 1 && *eptr != NEWLINE))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1414            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1415          ecode++;          ecode++;
1416          break;          break;
1417          }          }
1418        }        }
1419      /* ... else fall through */      /* ... else fall through for endonly */
1420    
1421      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1422    
# Line 1226  for (;;) Line 1428  for (;;)
1428      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1429    
1430      case OP_EODN:      case OP_EODN:
1431      if (eptr < md->end_subject - 1 ||      if (eptr != md->end_subject &&
1432         (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1433          RRETURN(MATCH_NOMATCH);
1434      ecode++;      ecode++;
1435      break;      break;
1436    
# Line 1280  for (;;) Line 1483  for (;;)
1483      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1484    
1485      case OP_ANY:      case OP_ANY:
1486      if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1487        RRETURN(MATCH_NOMATCH);      /* Fall through */
1488    
1489        case OP_ALLANY:
1490      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1491  #ifdef SUPPORT_UTF8      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
 #endif  
1492      ecode++;      ecode++;
1493      break;      break;
1494    
# Line 1376  for (;;) Line 1578  for (;;)
1578      ecode++;      ecode++;
1579      break;      break;
1580    
1581        case OP_ANYNL:
1582        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1583        GETCHARINCTEST(c, eptr);
1584        switch(c)
1585          {
1586          default: RRETURN(MATCH_NOMATCH);
1587          case 0x000d:
1588          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1589          break;
1590    
1591          case 0x000a:
1592          break;
1593    
1594          case 0x000b:
1595          case 0x000c:
1596          case 0x0085:
1597          case 0x2028:
1598          case 0x2029:
1599          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1600          break;
1601          }
1602        ecode++;
1603        break;
1604    
1605        case OP_NOT_HSPACE:
1606        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1607        GETCHARINCTEST(c, eptr);
1608        switch(c)
1609          {
1610          default: break;
1611          case 0x09:      /* HT */
1612          case 0x20:      /* SPACE */
1613          case 0xa0:      /* NBSP */
1614          case 0x1680:    /* OGHAM SPACE MARK */
1615          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1616          case 0x2000:    /* EN QUAD */
1617          case 0x2001:    /* EM QUAD */
1618          case 0x2002:    /* EN SPACE */
1619          case 0x2003:    /* EM SPACE */
1620          case 0x2004:    /* THREE-PER-EM SPACE */
1621          case 0x2005:    /* FOUR-PER-EM SPACE */
1622          case 0x2006:    /* SIX-PER-EM SPACE */
1623          case 0x2007:    /* FIGURE SPACE */
1624          case 0x2008:    /* PUNCTUATION SPACE */
1625          case 0x2009:    /* THIN SPACE */
1626          case 0x200A:    /* HAIR SPACE */
1627          case 0x202f:    /* NARROW NO-BREAK SPACE */
1628          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1629          case 0x3000:    /* IDEOGRAPHIC SPACE */
1630          RRETURN(MATCH_NOMATCH);
1631          }
1632        ecode++;
1633        break;
1634    
1635        case OP_HSPACE:
1636        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1637        GETCHARINCTEST(c, eptr);
1638        switch(c)
1639          {
1640          default: RRETURN(MATCH_NOMATCH);
1641          case 0x09:      /* HT */
1642          case 0x20:      /* SPACE */
1643          case 0xa0:      /* NBSP */
1644          case 0x1680:    /* OGHAM SPACE MARK */
1645          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1646          case 0x2000:    /* EN QUAD */
1647          case 0x2001:    /* EM QUAD */
1648          case 0x2002:    /* EN SPACE */
1649          case 0x2003:    /* EM SPACE */
1650          case 0x2004:    /* THREE-PER-EM SPACE */
1651          case 0x2005:    /* FOUR-PER-EM SPACE */
1652          case 0x2006:    /* SIX-PER-EM SPACE */
1653          case 0x2007:    /* FIGURE SPACE */
1654          case 0x2008:    /* PUNCTUATION SPACE */
1655          case 0x2009:    /* THIN SPACE */
1656          case 0x200A:    /* HAIR SPACE */
1657          case 0x202f:    /* NARROW NO-BREAK SPACE */
1658          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1659          case 0x3000:    /* IDEOGRAPHIC SPACE */
1660          break;
1661          }
1662        ecode++;
1663        break;
1664    
1665        case OP_NOT_VSPACE:
1666        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1667        GETCHARINCTEST(c, eptr);
1668        switch(c)
1669          {
1670          default: break;
1671          case 0x0a:      /* LF */
1672          case 0x0b:      /* VT */
1673          case 0x0c:      /* FF */
1674          case 0x0d:      /* CR */
1675          case 0x85:      /* NEL */
1676          case 0x2028:    /* LINE SEPARATOR */
1677          case 0x2029:    /* PARAGRAPH SEPARATOR */
1678          RRETURN(MATCH_NOMATCH);
1679          }
1680        ecode++;
1681        break;
1682    
1683        case OP_VSPACE:
1684        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1685        GETCHARINCTEST(c, eptr);
1686        switch(c)
1687          {
1688          default: RRETURN(MATCH_NOMATCH);
1689          case 0x0a:      /* LF */
1690          case 0x0b:      /* VT */
1691          case 0x0c:      /* FF */
1692          case 0x0d:      /* CR */
1693          case 0x85:      /* NEL */
1694          case 0x2028:    /* LINE SEPARATOR */
1695          case 0x2029:    /* PARAGRAPH SEPARATOR */
1696          break;
1697          }
1698        ecode++;
1699        break;
1700    
1701  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1702      /* Check the next character by Unicode property. We will get here only      /* Check the next character by Unicode property. We will get here only
1703      if the support is in the binary; otherwise a compile-time error occurs. */      if the support is in the binary; otherwise a compile-time error occurs. */
# Line 1385  for (;;) Line 1707  for (;;)
1707      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1708      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1709        {        {
1710        int chartype, script;        const ucd_record * prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1711    
1712        switch(ecode[1])        switch(ecode[1])
1713          {          {
# Line 1395  for (;;) Line 1716  for (;;)
1716          break;          break;
1717    
1718          case PT_LAMP:          case PT_LAMP:
1719          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1720               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1721               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1722            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1723           break;           break;
1724    
1725          case PT_GC:          case PT_GC:
1726          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1727            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1728          break;          break;
1729    
1730          case PT_PC:          case PT_PC:
1731          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1732            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1733          break;          break;
1734    
1735          case PT_SC:          case PT_SC:
1736          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1737            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1738          break;          break;
1739    
1740          default:          default:
1741          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
1742          }          }
1743    
1744        ecode += 3;        ecode += 3;
# Line 1432  for (;;) Line 1752  for (;;)
1752      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1753      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1754        {        {
1755        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1756        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1757        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1758          {          {
# Line 1442  for (;;) Line 1761  for (;;)
1761            {            {
1762            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1763            }            }
1764          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1765          if (category != ucp_M) break;          if (category != ucp_M) break;
1766          eptr += len;          eptr += len;
1767          }          }
# Line 1463  for (;;) Line 1782  for (;;)
1782      case OP_REF:      case OP_REF:
1783        {        {
1784        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1785        ecode += 3;                                 /* Advance past item */        ecode += 3;
1786    
1787          /* If the reference is unset, there are two possibilities:
1788    
1789          (a) In the default, Perl-compatible state, set the length to be longer
1790          than the amount of subject left; this ensures that every attempt at a
1791          match fails. We can't just fail here, because of the possibility of
1792          quantifiers with zero minima.
1793    
1794          (b) If the JavaScript compatibility flag is set, set the length to zero
1795          so that the back reference matches an empty string.
1796    
1797        /* If the reference is unset, set the length to be longer than the amount        Otherwise, set the length to the length of what was matched by the
1798        of subject left; this ensures that every attempt at a match fails. We        referenced subpattern. */
1799        can't just fail here, because of the possibility of quantifiers with zero  
1800        minima. */        if (offset >= offset_top || md->offset_vector[offset] < 0)
1801            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1802        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        else
1803          md->end_subject - eptr + 1 :          length = md->offset_vector[offset+1] - md->offset_vector[offset];
         md->offset_vector[offset+1] - md->offset_vector[offset];  
1804    
1805        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1806    
# Line 1532  for (;;) Line 1860  for (;;)
1860          {          {
1861          for (fi = min;; fi++)          for (fi = min;; fi++)
1862            {            {
1863            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1864            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1865            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max || !match_ref(offset, eptr, length, md, ims))
1866              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 1553  for (;;) Line 1881  for (;;)
1881            }            }
1882          while (eptr >= pp)          while (eptr >= pp)
1883            {            {
1884            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1885            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1886            eptr -= length;            eptr -= length;
1887            }            }
# Line 1658  for (;;) Line 1986  for (;;)
1986            {            {
1987            for (fi = min;; fi++)            for (fi = min;; fi++)
1988              {              {
1989              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
1990              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1991              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1992              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
# Line 1678  for (;;) Line 2006  for (;;)
2006            {            {
2007            for (fi = min;; fi++)            for (fi = min;; fi++)
2008              {              {
2009              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2010              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2011              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2012              c = *eptr++;              c = *eptr++;
# Line 1715  for (;;) Line 2043  for (;;)
2043              }              }
2044            for (;;)            for (;;)
2045              {              {
2046              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2047              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2048              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2049              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1734  for (;;) Line 2062  for (;;)
2062              }              }
2063            while (eptr >= pp)            while (eptr >= pp)
2064              {              {
2065              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2066              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2067              eptr--;              eptr--;
2068              }              }
# Line 1805  for (;;) Line 2133  for (;;)
2133          {          {
2134          for (fi = min;; fi++)          for (fi = min;; fi++)
2135            {            {
2136            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2137            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2138            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2139            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
# Line 1829  for (;;) Line 2157  for (;;)
2157            }            }
2158          for(;;)          for(;;)
2159            {            {
2160            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2161            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2162            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2163            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2164            }            }
2165          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2166          }          }
# Line 1888  for (;;) Line 2216  for (;;)
2216    
2217        else        else
2218          {          {
2219          int dc;          unsigned int dc;
2220          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2221          ecode += length;          ecode += length;
2222    
# Line 1898  for (;;) Line 2226  for (;;)
2226          if (fc != dc)          if (fc != dc)
2227            {            {
2228  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2229            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2230  #endif  #endif
2231              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2232            }            }
# Line 1915  for (;;) Line 2243  for (;;)
2243        }        }
2244      break;      break;
2245    
2246      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2247    
2248      case OP_EXACT:      case OP_EXACT:
2249      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2250      ecode += 3;      ecode += 3;
2251      goto REPEATCHAR;      goto REPEATCHAR;
2252    
2253        case OP_POSUPTO:
2254        possessive = TRUE;
2255        /* Fall through */
2256    
2257      case OP_UPTO:      case OP_UPTO:
2258      case OP_MINUPTO:      case OP_MINUPTO:
2259      min = 0;      min = 0;
# Line 1930  for (;;) Line 2262  for (;;)
2262      ecode += 3;      ecode += 3;
2263      goto REPEATCHAR;      goto REPEATCHAR;
2264    
2265        case OP_POSSTAR:
2266        possessive = TRUE;
2267        min = 0;
2268        max = INT_MAX;
2269        ecode++;
2270        goto REPEATCHAR;
2271    
2272        case OP_POSPLUS:
2273        possessive = TRUE;
2274        min = 1;
2275        max = INT_MAX;
2276        ecode++;
2277        goto REPEATCHAR;
2278    
2279        case OP_POSQUERY:
2280        possessive = TRUE;
2281        min = 0;
2282        max = 1;
2283        ecode++;
2284        goto REPEATCHAR;
2285    
2286      case OP_STAR:      case OP_STAR:
2287      case OP_MINSTAR:      case OP_MINSTAR:
2288      case OP_PLUS:      case OP_PLUS:
# Line 1961  for (;;) Line 2314  for (;;)
2314    
2315        if (length > 1)        if (length > 1)
2316          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2317  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2318          int othercase;          unsigned int othercase;
2319          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2320              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2321            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2322            else oclength = 0;
2323  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2324    
2325          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2326            {            {
2327            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (memcmp(eptr, charptr, length) == 0) eptr += length;
2328    #ifdef SUPPORT_UCP
2329            /* Need braces because of following else */            /* Need braces because of following else */
2330            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2331            else            else
# Line 1982  for (;;) Line 2333  for (;;)
2333              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2334              eptr += oclength;              eptr += oclength;
2335              }              }
2336    #else   /* without SUPPORT_UCP */
2337              else { RRETURN(MATCH_NOMATCH); }
2338    #endif  /* SUPPORT_UCP */
2339            }            }
2340    
2341          if (min == max) continue;          if (min == max) continue;
# Line 1990  for (;;) Line 2344  for (;;)
2344            {            {
2345            for (fi = min;; fi++)            for (fi = min;; fi++)
2346              {              {
2347              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2348              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2349              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2350              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2351    #ifdef SUPPORT_UCP
2352              /* Need braces because of following else */              /* Need braces because of following else */
2353              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2354              else              else
# Line 2001  for (;;) Line 2356  for (;;)
2356                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2357                eptr += oclength;                eptr += oclength;
2358                }                }
2359    #else   /* without SUPPORT_UCP */
2360                else { RRETURN (MATCH_NOMATCH); }
2361    #endif  /* SUPPORT_UCP */
2362              }              }
2363            /* Control never gets here */            /* Control never gets here */
2364            }            }
2365          else  
2366            else  /* Maximize */
2367            {            {
2368            pp = eptr;            pp = eptr;
2369            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2370              {              {
2371              if (eptr > md->end_subject - length) break;              if (eptr > md->end_subject - length) break;
2372              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2373    #ifdef SUPPORT_UCP
2374              else if (oclength == 0) break;              else if (oclength == 0) break;
2375              else              else
2376                {                {
2377                if (memcmp(eptr, occhars, oclength) != 0) break;                if (memcmp(eptr, occhars, oclength) != 0) break;
2378                eptr += oclength;                eptr += oclength;
2379                }                }
2380    #else   /* without SUPPORT_UCP */
2381                else break;
2382    #endif  /* SUPPORT_UCP */
2383              }              }
2384            while (eptr >= pp)  
2385              if (possessive) continue;
2386              for(;;)
2387             {             {
2388             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2389             if (rrc != MATCH_NOMATCH) RRETURN(rrc);             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2390               if (eptr == pp) RRETURN(MATCH_NOMATCH);
2391    #ifdef SUPPORT_UCP
2392               eptr--;
2393               BACKCHAR(eptr);
2394    #else   /* without SUPPORT_UCP */
2395             eptr -= length;             eptr -= length;
2396    #endif  /* SUPPORT_UCP */
2397             }             }
           RRETURN(MATCH_NOMATCH);  
2398            }            }
2399          /* Control never gets here */          /* Control never gets here */
2400          }          }
# Line 2064  for (;;) Line 2434  for (;;)
2434          {          {
2435          for (fi = min;; fi++)          for (fi = min;; fi++)
2436            {            {
2437            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2438            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2439            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
2440                fc != md->lcc[*eptr++])                fc != md->lcc[*eptr++])
# Line 2072  for (;;) Line 2442  for (;;)
2442            }            }
2443          /* Control never gets here */          /* Control never gets here */
2444          }          }
2445        else        else  /* Maximize */
2446          {          {
2447          pp = eptr;          pp = eptr;
2448          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2080  for (;;) Line 2450  for (;;)
2450            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2451            eptr++;            eptr++;
2452            }            }
2453            if (possessive) continue;
2454          while (eptr >= pp)          while (eptr >= pp)
2455            {            {
2456            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2457            eptr--;            eptr--;
2458            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2459            }            }
# Line 2101  for (;;) Line 2472  for (;;)
2472          {          {
2473          for (fi = min;; fi++)          for (fi = min;; fi++)
2474            {            {
2475            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2476            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2477            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
2478              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2479            }            }
2480          /* Control never gets here */          /* Control never gets here */
2481          }          }
2482        else        else  /* Maximize */
2483          {          {
2484          pp = eptr;          pp = eptr;
2485          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2116  for (;;) Line 2487  for (;;)
2487            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2488            eptr++;            eptr++;
2489            }            }
2490            if (possessive) continue;
2491          while (eptr >= pp)          while (eptr >= pp)
2492            {            {
2493            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2494            eptr--;            eptr--;
2495            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2496            }            }
# Line 2168  for (;;) Line 2540  for (;;)
2540      ecode += 3;      ecode += 3;
2541      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2542    
2543        case OP_NOTPOSSTAR:
2544        possessive = TRUE;
2545        min = 0;
2546        max = INT_MAX;
2547        ecode++;
2548        goto REPEATNOTCHAR;
2549    
2550        case OP_NOTPOSPLUS:
2551        possessive = TRUE;
2552        min = 1;
2553        max = INT_MAX;
2554        ecode++;
2555        goto REPEATNOTCHAR;
2556    
2557        case OP_NOTPOSQUERY:
2558        possessive = TRUE;
2559        min = 0;
2560        max = 1;
2561        ecode++;
2562        goto REPEATNOTCHAR;
2563    
2564        case OP_NOTPOSUPTO:
2565        possessive = TRUE;
2566        min = 0;
2567        max = GET2(ecode, 1);
2568        ecode += 3;
2569        goto REPEATNOTCHAR;
2570    
2571      case OP_NOTSTAR:      case OP_NOTSTAR:
2572      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2573      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2207  for (;;) Line 2607  for (;;)
2607        /* UTF-8 mode */        /* UTF-8 mode */
2608        if (utf8)        if (utf8)
2609          {          {
2610          register int d;          register unsigned int d;
2611          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2612            {            {
2613            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2232  for (;;) Line 2632  for (;;)
2632          /* UTF-8 mode */          /* UTF-8 mode */
2633          if (utf8)          if (utf8)
2634            {            {
2635            register int d;            register unsigned int d;
2636            for (fi = min;; fi++)            for (fi = min;; fi++)
2637              {              {
2638              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2639              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2640                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2641              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2642              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2643              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2644                RRETURN(MATCH_NOMATCH);  
2645              }              }
2646            }            }
2647          else          else
# Line 2249  for (;;) Line 2650  for (;;)
2650            {            {
2651            for (fi = min;; fi++)            for (fi = min;; fi++)
2652              {              {
2653              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2654              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2655              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
2656                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2268  for (;;) Line 2669  for (;;)
2669          /* UTF-8 mode */          /* UTF-8 mode */
2670          if (utf8)          if (utf8)
2671            {            {
2672            register int d;            register unsigned int d;
2673            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2674              {              {
2675              int len = 1;              int len = 1;
# Line 2278  for (;;) Line 2679  for (;;)
2679              if (fc == d) break;              if (fc == d) break;
2680              eptr += len;              eptr += len;
2681              }              }
2682            for(;;)          if (possessive) continue;
2683            for(;;)
2684              {              {
2685              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2686              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2687              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2688              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2295  for (;;) Line 2697  for (;;)
2697              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2698              eptr++;              eptr++;
2699              }              }
2700              if (possessive) continue;
2701            while (eptr >= pp)            while (eptr >= pp)
2702              {              {
2703              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2704              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2705              eptr--;              eptr--;
2706              }              }
# Line 2316  for (;;) Line 2719  for (;;)
2719        /* UTF-8 mode */        /* UTF-8 mode */
2720        if (utf8)        if (utf8)
2721          {          {
2722          register int d;          register unsigned int d;
2723          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2724            {            {
2725            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2339  for (;;) Line 2742  for (;;)
2742          /* UTF-8 mode */          /* UTF-8 mode */
2743          if (utf8)          if (utf8)
2744            {            {
2745            register int d;            register unsigned int d;
2746            for (fi = min;; fi++)            for (fi = min;; fi++)
2747              {              {
2748              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2749              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2750                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2751              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2752              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2753              }              }
2754            }            }
2755          else          else
# Line 2355  for (;;) Line 2758  for (;;)
2758            {            {
2759            for (fi = min;; fi++)            for (fi = min;; fi++)
2760              {              {
2761              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2762              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2763              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
2764                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2374  for (;;) Line 2777  for (;;)
2777          /* UTF-8 mode */          /* UTF-8 mode */
2778          if (utf8)          if (utf8)
2779            {            {
2780            register int d;            register unsigned int d;
2781            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2782              {              {
2783              int len = 1;              int len = 1;
# Line 2383  for (;;) Line 2786  for (;;)
2786              if (fc == d) break;              if (fc == d) break;
2787              eptr += len;              eptr += len;
2788              }              }
2789              if (possessive) continue;
2790            for(;;)            for(;;)
2791              {              {
2792              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
2793              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2794              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2795              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2400  for (;;) Line 2804  for (;;)
2804              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
2805              eptr++;              eptr++;
2806              }              }
2807              if (possessive) continue;
2808            while (eptr >= pp)            while (eptr >= pp)
2809              {              {
2810              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
2811              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2812              eptr--;              eptr--;
2813              }              }
# Line 2431  for (;;) Line 2836  for (;;)
2836      ecode += 3;      ecode += 3;
2837      goto REPEATTYPE;      goto REPEATTYPE;
2838    
2839        case OP_TYPEPOSSTAR:
2840        possessive = TRUE;
2841        min = 0;
2842        max = INT_MAX;
2843        ecode++;
2844        goto REPEATTYPE;
2845    
2846        case OP_TYPEPOSPLUS:
2847        possessive = TRUE;
2848        min = 1;
2849        max = INT_MAX;
2850        ecode++;
2851        goto REPEATTYPE;
2852    
2853        case OP_TYPEPOSQUERY:
2854        possessive = TRUE;
2855        min = 0;
2856        max = 1;
2857        ecode++;
2858        goto REPEATTYPE;
2859    
2860        case OP_TYPEPOSUPTO:
2861        possessive = TRUE;
2862        min = 0;
2863        max = GET2(ecode, 1);
2864        ecode += 3;
2865        goto REPEATTYPE;
2866    
2867      case OP_TYPESTAR:      case OP_TYPESTAR:
2868      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
2869      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2481  for (;;) Line 2914  for (;;)
2914            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2915              {              {
2916              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2917              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2918              }              }
2919            break;            break;
2920    
# Line 2489  for (;;) Line 2922  for (;;)
2922            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2923              {              {
2924              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2925              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2926              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2927              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2928                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2929                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2502  for (;;) Line 2935  for (;;)
2935            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2936              {              {
2937              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2938              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2939              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2940              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2941                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2942              }              }
# Line 2513  for (;;) Line 2946  for (;;)
2946            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2947              {              {
2948              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2949              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2950              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2951              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2952                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2953              }              }
# Line 2524  for (;;) Line 2957  for (;;)
2957            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2958              {              {
2959              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2960              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2961              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2962              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2963                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2964              }              }
# Line 2533  for (;;) Line 2966  for (;;)
2966    
2967            default:            default:
2968            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
2969            }            }
2970          }          }
2971    
# Line 2545  for (;;) Line 2977  for (;;)
2977          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2978            {            {
2979            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2980            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2981            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2982            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2983              {              {
# Line 2554  for (;;) Line 2986  for (;;)
2986                {                {
2987                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2988                }                }
2989              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2990              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
2991              eptr += len;              eptr += len;
2992              }              }
# Line 2572  for (;;) Line 3004  for (;;)
3004          case OP_ANY:          case OP_ANY:
3005          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3006            {            {
3007            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
              (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0))  
3008              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3009              eptr++;
3010              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3011              }
3012            break;
3013    
3014            case OP_ALLANY:
3015            for (i = 1; i <= min; i++)
3016              {
3017              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3018              eptr++;
3019            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3020            }            }
3021          break;          break;
# Line 2583  for (;;) Line 3024  for (;;)
3024          eptr += min;          eptr += min;
3025          break;          break;
3026    
3027            case OP_ANYNL:
3028            for (i = 1; i <= min; i++)
3029              {
3030              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3031              GETCHARINC(c, eptr);
3032              switch(c)
3033                {
3034                default: RRETURN(MATCH_NOMATCH);
3035                case 0x000d:
3036                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3037                break;
3038    
3039                case 0x000a:
3040                break;
3041    
3042                case 0x000b:
3043                case 0x000c:
3044                case 0x0085:
3045                case 0x2028:
3046                case 0x2029:
3047                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3048                break;
3049                }
3050              }
3051            break;
3052    
3053            case OP_NOT_HSPACE:
3054            for (i = 1; i <= min; i++)
3055              {
3056              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3057              GETCHARINC(c, eptr);
3058              switch(c)
3059                {
3060                default: break;
3061                case 0x09:      /* HT */
3062                case 0x20:      /* SPACE */
3063                case 0xa0:      /* NBSP */
3064                case 0x1680:    /* OGHAM SPACE MARK */
3065                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3066                case 0x2000:    /* EN QUAD */
3067                case 0x2001:    /* EM QUAD */
3068                case 0x2002:    /* EN SPACE */
3069                case 0x2003:    /* EM SPACE */
3070                case 0x2004:    /* THREE-PER-EM SPACE */
3071                case 0x2005:    /* FOUR-PER-EM SPACE */
3072                case 0x2006:    /* SIX-PER-EM SPACE */
3073                case 0x2007:    /* FIGURE SPACE */
3074                case 0x2008:    /* PUNCTUATION SPACE */
3075                case 0x2009:    /* THIN SPACE */
3076                case 0x200A:    /* HAIR SPACE */
3077                case 0x202f:    /* NARROW NO-BREAK SPACE */
3078                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3079                case 0x3000:    /* IDEOGRAPHIC SPACE */
3080                RRETURN(MATCH_NOMATCH);
3081                }
3082              }
3083            break;
3084    
3085            case OP_HSPACE:
3086            for (i = 1; i <= min; i++)
3087              {
3088              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3089              GETCHARINC(c, eptr);
3090              switch(c)
3091                {
3092                default: RRETURN(MATCH_NOMATCH);
3093                case 0x09:      /* HT */
3094                case 0x20:      /* SPACE */
3095                case 0xa0:      /* NBSP */
3096                case 0x1680:    /* OGHAM SPACE MARK */
3097                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3098                case 0x2000:    /* EN QUAD */
3099                case 0x2001:    /* EM QUAD */
3100                case 0x2002:    /* EN SPACE */
3101                case 0x2003:    /* EM SPACE */
3102                case 0x2004:    /* THREE-PER-EM SPACE */
3103                case 0x2005:    /* FOUR-PER-EM SPACE */
3104                case 0x2006:    /* SIX-PER-EM SPACE */
3105                case 0x2007:    /* FIGURE SPACE */
3106                case 0x2008:    /* PUNCTUATION SPACE */
3107                case 0x2009:    /* THIN SPACE */
3108                case 0x200A:    /* HAIR SPACE */
3109                case 0x202f:    /* NARROW NO-BREAK SPACE */
3110                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3111                case 0x3000:    /* IDEOGRAPHIC SPACE */
3112                break;
3113                }
3114              }
3115            break;
3116    
3117            case OP_NOT_VSPACE:
3118            for (i = 1; i <= min; i++)
3119              {
3120              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3121              GETCHARINC(c, eptr);
3122              switch(c)
3123                {
3124                default: break;
3125                case 0x0a:      /* LF */
3126                case 0x0b:      /* VT */
3127                case 0x0c:      /* FF */
3128                case 0x0d:      /* CR */
3129                case 0x85:      /* NEL */
3130                case 0x2028:    /* LINE SEPARATOR */
3131                case 0x2029:    /* PARAGRAPH SEPARATOR */
3132                RRETURN(MATCH_NOMATCH);
3133                }
3134              }
3135            break;
3136    
3137            case OP_VSPACE:
3138            for (i = 1; i <= min; i++)
3139              {
3140              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3141              GETCHARINC(c, eptr);
3142              switch(c)
3143                {
3144                default: RRETURN(MATCH_NOMATCH);
3145                case 0x0a:      /* LF */
3146                case 0x0b:      /* VT */
3147                case 0x0c:      /* FF */
3148                case 0x0d:      /* CR */
3149                case 0x85:      /* NEL */
3150                case 0x2028:    /* LINE SEPARATOR */
3151                case 0x2029:    /* PARAGRAPH SEPARATOR */
3152                break;
3153                }
3154              }
3155            break;
3156    
3157          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3158          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3159            {            {
# Line 2607  for (;;) Line 3178  for (;;)
3178          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3179            {            {
3180            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3181               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3182              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3183            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3184            }            }
3185          break;          break;
3186    
# Line 2627  for (;;) Line 3198  for (;;)
3198          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3199            {            {
3200            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3201               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3202              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3203            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3204            }            }
3205          break;          break;
3206    
# Line 2651  for (;;) Line 3222  for (;;)
3222  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3223    
3224        /* Code for the non-UTF-8 case for minimum matching of operators other        /* Code for the non-UTF-8 case for minimum matching of operators other
3225        than OP_PROP and OP_NOTPROP. */        than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
3226          number of bytes present, as this was tested above. */
3227    
3228        switch(ctype)        switch(ctype)
3229          {          {
3230          case OP_ANY:          case OP_ANY:
3231          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3232            {            {
3233            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3234              if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH);            eptr++;
3235            }            }
3236          else eptr += min;          break;
3237    
3238            case OP_ALLANY:
3239            eptr += min;
3240          break;          break;
3241    
3242          case OP_ANYBYTE:          case OP_ANYBYTE:
3243          eptr += min;          eptr += min;
3244          break;          break;
3245    
3246            /* Because of the CRLF case, we can't assume the minimum number of
3247            bytes are present in this case. */
3248    
3249            case OP_ANYNL:
3250            for (i = 1; i <= min; i++)
3251              {
3252              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3253              switch(*eptr++)
3254                {
3255                default: RRETURN(MATCH_NOMATCH);
3256                case 0x000d:
3257                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3258                break;
3259                case 0x000a:
3260                break;
3261    
3262                case 0x000b:
3263                case 0x000c:
3264                case 0x0085:
3265                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3266                break;
3267                }
3268              }
3269            break;
3270    
3271            case OP_NOT_HSPACE:
3272            for (i = 1; i <= min; i++)
3273              {
3274              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3275              switch(*eptr++)
3276                {
3277                default: break;
3278                case 0x09:      /* HT */
3279                case 0x20:      /* SPACE */
3280                case 0xa0:      /* NBSP */
3281                RRETURN(MATCH_NOMATCH);
3282                }
3283              }
3284            break;
3285    
3286            case OP_HSPACE:
3287            for (i = 1; i <= min; i++)
3288              {
3289              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3290              switch(*eptr++)
3291                {
3292                default: RRETURN(MATCH_NOMATCH);
3293                case 0x09:      /* HT */
3294                case 0x20:      /* SPACE */
3295                case 0xa0:      /* NBSP */
3296                break;
3297                }
3298              }
3299            break;
3300    
3301            case OP_NOT_VSPACE:
3302            for (i = 1; i <= min; i++)
3303              {
3304              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3305              switch(*eptr++)
3306                {
3307                default: break;
3308                case 0x0a:      /* LF */
3309                case 0x0b:      /* VT */
3310                case 0x0c:      /* FF */
3311                case 0x0d:      /* CR */
3312                case 0x85:      /* NEL */
3313                RRETURN(MATCH_NOMATCH);
3314                }
3315              }
3316            break;
3317    
3318            case OP_VSPACE:
3319            for (i = 1; i <= min; i++)
3320              {
3321              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3322              switch(*eptr++)
3323                {
3324                default: RRETURN(MATCH_NOMATCH);
3325                case 0x0a:      /* LF */
3326                case 0x0b:      /* VT */
3327                case 0x0c:      /* FF */
3328                case 0x0d:      /* CR */
3329                case 0x85:      /* NEL */
3330                break;
3331                }
3332              }
3333            break;
3334    
3335          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3336          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3337            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
# Line 2723  for (;;) Line 3387  for (;;)
3387            case PT_ANY:            case PT_ANY:
3388            for (fi = min;; fi++)            for (fi = min;; fi++)
3389              {              {
3390              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3391              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3392              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3393              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3394              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3395              }              }
3396            break;            /* Control never gets here */
3397    
3398            case PT_LAMP:            case PT_LAMP:
3399            for (fi = min;; fi++)            for (fi = min;; fi++)
3400              {              {
3401              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3402              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3403              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3404              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3405              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3406              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3407                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3408                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3409                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3410              }              }
3411            break;            /* Control never gets here */
3412    
3413            case PT_GC:            case PT_GC:
3414            for (fi = min;; fi++)            for (fi = min;; fi++)
3415              {              {
3416              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3417              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3418              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3419              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3420              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3421              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3422                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3423              }              }
3424            break;            /* Control never gets here */
3425    
3426            case PT_PC:            case PT_PC:
3427            for (fi = min;; fi++)            for (fi = min;; fi++)
3428              {              {
3429              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3430              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3431              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3432              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3433              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3434              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3435                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3436              }              }
3437            break;            /* Control never gets here */
3438    
3439            case PT_SC:            case PT_SC:
3440            for (fi = min;; fi++)            for (fi = min;; fi++)
3441              {              {
3442              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3443              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3444              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3445              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3446              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3447              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3448                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3449              }              }
3450            break;            /* Control never gets here */
3451    
3452            default:            default:
3453            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3454            }            }
3455          }          }
3456    
# Line 2798  for (;;) Line 3461  for (;;)
3461          {          {
3462          for (fi = min;; fi++)          for (fi = min;; fi++)
3463            {            {
3464            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3465            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3466            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3467            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3468            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3469            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3470            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3471              {              {
# Line 2811  for (;;) Line 3474  for (;;)
3474                {                {
3475                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3476                }                }
3477              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3478              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3479              eptr += len;              eptr += len;
3480              }              }
# Line 2827  for (;;) Line 3490  for (;;)
3490          {          {
3491          for (fi = min;; fi++)          for (fi = min;; fi++)
3492            {            {
3493            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3494            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3495            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3496                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3497                RRETURN(MATCH_NOMATCH);
3498    
3499            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3500            switch(ctype)            switch(ctype)
3501              {              {
3502              case OP_ANY:              case OP_ANY:        /* This is the non-NL case */
3503              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3504                case OP_ANYBYTE:
3505              break;              break;
3506    
3507              case OP_ANYBYTE:              case OP_ANYNL:
3508                switch(c)
3509                  {
3510                  default: RRETURN(MATCH_NOMATCH);
3511                  case 0x000d:
3512                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3513                  break;
3514                  case 0x000a:
3515                  break;
3516    
3517                  case 0x000b:
3518                  case 0x000c:
3519                  case 0x0085:
3520                  case 0x2028:
3521                  case 0x2029:
3522                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3523                  break;
3524                  }
3525                break;
3526    
3527                case OP_NOT_HSPACE:
3528                switch(c)
3529                  {
3530                  default: break;
3531                  case 0x09:      /* HT */
3532                  case 0x20:      /* SPACE */
3533                  case 0xa0:      /* NBSP */
3534                  case 0x1680:    /* OGHAM SPACE MARK */
3535                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3536                  case 0x2000:    /* EN QUAD */
3537                  case 0x2001:    /* EM QUAD */
3538                  case 0x2002:    /* EN SPACE */
3539                  case 0x2003:    /* EM SPACE */
3540                  case 0x2004:    /* THREE-PER-EM SPACE */
3541                  case 0x2005:    /* FOUR-PER-EM SPACE */
3542                  case 0x2006:    /* SIX-PER-EM SPACE */
3543                  case 0x2007:    /* FIGURE SPACE */
3544                  case 0x2008:    /* PUNCTUATION SPACE */
3545                  case 0x2009:    /* THIN SPACE */
3546                  case 0x200A:    /* HAIR SPACE */
3547                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3548                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3549                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3550                  RRETURN(MATCH_NOMATCH);
3551                  }
3552                break;
3553    
3554                case OP_HSPACE:
3555                switch(c)
3556                  {
3557                  default: RRETURN(MATCH_NOMATCH);
3558                  case 0x09:      /* HT */
3559                  case 0x20:      /* SPACE */
3560                  case 0xa0:      /* NBSP */
3561                  case 0x1680:    /* OGHAM SPACE MARK */
3562                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3563                  case 0x2000:    /* EN QUAD */
3564                  case 0x2001:    /* EM QUAD */
3565                  case 0x2002:    /* EN SPACE */
3566                  case 0x2003:    /* EM SPACE */
3567                  case 0x2004:    /* THREE-PER-EM SPACE */
3568                  case 0x2005:    /* FOUR-PER-EM SPACE */
3569                  case 0x2006:    /* SIX-PER-EM SPACE */
3570                  case 0x2007:    /* FIGURE SPACE */
3571                  case 0x2008:    /* PUNCTUATION SPACE */
3572                  case 0x2009:    /* THIN SPACE */
3573                  case 0x200A:    /* HAIR SPACE */
3574                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3575                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3576                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3577                  break;
3578                  }
3579                break;
3580    
3581                case OP_NOT_VSPACE:
3582                switch(c)
3583                  {
3584                  default: break;
3585                  case 0x0a:      /* LF */
3586                  case 0x0b:      /* VT */
3587                  case 0x0c:      /* FF */
3588                  case 0x0d:      /* CR */
3589                  case 0x85:      /* NEL */
3590                  case 0x2028:    /* LINE SEPARATOR */
3591                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3592                  RRETURN(MATCH_NOMATCH);
3593                  }
3594                break;
3595    
3596                case OP_VSPACE:
3597                switch(c)
3598                  {
3599                  default: RRETURN(MATCH_NOMATCH);
3600                  case 0x0a:      /* LF */
3601                  case 0x0b:      /* VT */
3602                  case 0x0c:      /* FF */
3603                  case 0x0d:      /* CR */
3604                  case 0x85:      /* NEL */
3605                  case 0x2028:    /* LINE SEPARATOR */
3606                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3607                  break;
3608                  }
3609              break;              break;
3610    
3611              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2882  for (;;) Line 3649  for (;;)
3649          {          {
3650          for (fi = min;; fi++)          for (fi = min;; fi++)
3651            {            {
3652            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3653            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3654            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3655                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3656                RRETURN(MATCH_NOMATCH);
3657    
3658            c = *eptr++;            c = *eptr++;
3659            switch(ctype)            switch(ctype)
3660              {              {
3661              case OP_ANY:              case OP_ANY:     /* This is the non-NL case */
3662              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3663                case OP_ANYBYTE:
3664              break;              break;
3665    
3666              case OP_ANYBYTE:              case OP_ANYNL:
3667                switch(c)
3668                  {
3669                  default: RRETURN(MATCH_NOMATCH);
3670                  case 0x000d:
3671                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3672                  break;
3673    
3674                  case 0x000a:
3675                  break;
3676    
3677                  case 0x000b:
3678                  case 0x000c:
3679                  case 0x0085:
3680                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3681                  break;
3682                  }
3683                break;
3684    
3685                case OP_NOT_HSPACE:
3686                switch(c)
3687                  {
3688                  default: break;
3689                  case 0x09:      /* HT */
3690                  case 0x20:      /* SPACE */
3691                  case 0xa0:      /* NBSP */
3692                  RRETURN(MATCH_NOMATCH);
3693                  }
3694                break;
3695    
3696                case OP_HSPACE:
3697                switch(c)
3698                  {
3699                  default: RRETURN(MATCH_NOMATCH);
3700                  case 0x09:      /* HT */
3701                  case 0x20:      /* SPACE */
3702                  case 0xa0:      /* NBSP */
3703                  break;
3704                  }
3705                break;
3706    
3707                case OP_NOT_VSPACE:
3708                switch(c)
3709                  {
3710                  default: break;
3711                  case 0x0a:      /* LF */
3712                  case 0x0b:      /* VT */
3713                  case 0x0c:      /* FF */
3714                  case 0x0d:      /* CR */
3715                  case 0x85:      /* NEL */
3716                  RRETURN(MATCH_NOMATCH);
3717                  }
3718                break;
3719    
3720                case OP_VSPACE:
3721                switch(c)
3722                  {
3723                  default: RRETURN(MATCH_NOMATCH);
3724                  case 0x0a:      /* LF */
3725                  case 0x0b:      /* VT */
3726                  case 0x0c:      /* FF */
3727                  case 0x0d:      /* CR */
3728                  case 0x85:      /* NEL */
3729                  break;
3730                  }
3731              break;              break;
3732    
3733              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2927  for (;;) Line 3762  for (;;)
3762        /* Control never gets here */        /* Control never gets here */
3763        }        }
3764    
3765      /* If maximizing it is worth using inline code for speed, doing the type      /* If maximizing, it is worth using inline code for speed, doing the type
3766      test once at the start (i.e. keep it out of the loop). Again, keep the      test once at the start (i.e. keep it out of the loop). Again, keep the
3767      UTF-8 and UCP stuff separate. */      UTF-8 and UCP stuff separate. */
3768    
# Line 2957  for (;;) Line 3792  for (;;)
3792              int len = 1;              int len = 1;
3793              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3794              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3795              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3796              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3797                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3798                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2972  for (;;) Line 3807  for (;;)
3807              int len = 1;              int len = 1;
3808              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3809              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3810              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3811              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3812                break;                break;
3813              eptr+= len;              eptr+= len;
# Line 2985  for (;;) Line 3820  for (;;)
3820              int len = 1;              int len = 1;
3821              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3822              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3823              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3824              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3825                break;                break;
3826              eptr+= len;              eptr+= len;
# Line 2998  for (;;) Line 3833  for (;;)
3833              int len = 1;              int len = 1;
3834              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3835              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3836              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3837              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3838                break;                break;
3839              eptr+= len;              eptr+= len;
# Line 3008  for (;;) Line 3843  for (;;)
3843    
3844          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3845    
3846            if (possessive) continue;
3847          for(;;)          for(;;)
3848            {            {
3849            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3850            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3851            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3852            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3853            }            }
3854          }          }
3855    
# Line 3026  for (;;) Line 3862  for (;;)
3862            {            {
3863            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3864            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3865            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3866            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3867            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3868              {              {
# Line 3035  for (;;) Line 3871  for (;;)
3871                {                {
3872                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3873                }                }
3874              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3875              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3876              eptr += len;              eptr += len;
3877              }              }
# Line 3043  for (;;) Line 3879  for (;;)
3879    
3880          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3881    
3882            if (possessive) continue;
3883          for(;;)          for(;;)
3884            {            {
3885            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
3886            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3887            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3888            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3889              {              {
3890              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3891              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3892                {                {
3893                  BACKCHAR(eptr);
3894                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3895                }                }
3896              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3897              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3898              eptr--;              eptr--;
3899              }              }
# Line 3074  for (;;) Line 3911  for (;;)
3911          switch(ctype)          switch(ctype)
3912            {            {
3913            case OP_ANY:            case OP_ANY:
   
           /* Special code is required for UTF8, but when the maximum is unlimited  
           we don't need it, so we repeat the non-UTF8 code. This is probably  
           worth it, because .* is quite a common idiom. */  
   
3914            if (max < INT_MAX)            if (max < INT_MAX)
3915              {              {
3916              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || *eptr == NEWLINE) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
3917                {                {
3918                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3919                  {                eptr++;
3920                  eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3921                }                }
3922              }              }
3923    
# Line 3104  for (;;) Line 3925  for (;;)
3925    
3926            else            else
3927              {              {
3928              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3929                {                {
3930                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3931                  {                eptr++;
3932                  if (eptr >= md->end_subject || *eptr == NEWLINE) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
3933                }                }
3934              else              }
3935              break;
3936    
3937              case OP_ALLANY:
3938              if (max < INT_MAX)
3939                {
3940                for (i = min; i < max; i++)
3941                {                {
3942                c = max - min;                if (eptr >= md->end_subject) break;
3943                if (c > md->end_subject - eptr) c = md->end_subject - eptr;                eptr++;
3944                eptr += c;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3945                }                }
3946              }              }
3947              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3948            break;            break;
3949    
3950            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
3951    
3952            case OP_ANYBYTE:            case OP_ANYBYTE:
3953            c = max - min;            c = max - min;
3954            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
3955                c = md->end_subject - eptr;
3956            eptr += c;            eptr += c;
3957            break;            break;
3958    
3959              case OP_ANYNL:
3960              for (i = min; i < max; i++)
3961                {
3962                int len = 1;
3963                if (eptr >= md->end_subject) break;
3964                GETCHARLEN(c, eptr, len);
3965                if (c == 0x000d)
3966                  {
3967                  if (++eptr >= md->end_subject) break;
3968                  if (*eptr == 0x000a) eptr++;
3969                  }
3970                else
3971                  {
3972                  if (c != 0x000a &&
3973                      (md->bsr_anycrlf ||
3974                       (c != 0x000b && c != 0x000c &&
3975                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3976                    break;
3977                  eptr += len;
3978                  }
3979                }
3980              break;
3981    
3982              case OP_NOT_HSPACE:
3983              case OP_HSPACE:
3984              for (i = min; i < max; i++)
3985                {
3986                BOOL gotspace;
3987                int len = 1;
3988                if (eptr >= md->end_subject) break;
3989                GETCHARLEN(c, eptr, len);
3990                switch(c)
3991                  {
3992                  default: gotspace = FALSE; break;
3993                  case 0x09:      /* HT */
3994                  case 0x20:      /* SPACE */
3995                  case 0xa0:      /* NBSP */
3996                  case 0x1680:    /* OGHAM SPACE MARK */
3997                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3998                  case 0x2000:    /* EN QUAD */
3999                  case 0x2001:    /* EM QUAD */
4000                  case 0x2002:    /* EN SPACE */
4001                  case 0x2003:    /* EM SPACE */
4002                  case 0x2004:    /* THREE-PER-EM SPACE */
4003                  case 0x2005:    /* FOUR-PER-EM SPACE */
4004                  case 0x2006:    /* SIX-PER-EM SPACE */
4005                  case 0x2007:    /* FIGURE SPACE */
4006                  case 0x2008:    /* PUNCTUATION SPACE */
4007                  case 0x2009:    /* THIN SPACE */
4008                  case 0x200A:    /* HAIR SPACE */
4009                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4010                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4011                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4012                  gotspace = TRUE;
4013                  break;
4014                  }
4015                if (gotspace == (ctype == OP_NOT_HSPACE)) break;
4016                eptr += len;
4017                }
4018              break;
4019    
4020              case OP_NOT_VSPACE:
4021              case OP_VSPACE:
4022              for (i = min; i < max; i++)
4023                {
4024                BOOL gotspace;
4025                int len = 1;
4026                if (eptr >= md->end_subject) break;
4027                GETCHARLEN(c, eptr, len);
4028                switch(c)
4029                  {
4030                  default: gotspace = FALSE; break;
4031                  case 0x0a:      /* LF */
4032                  case 0x0b:      /* VT */
4033                  case 0x0c:      /* FF */
4034                  case 0x0d:      /* CR */
4035                  case 0x85:      /* NEL */
4036                  case 0x2028:    /* LINE SEPARATOR */
4037                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4038                  gotspace = TRUE;
4039                  break;
4040                  }
4041                if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4042                eptr += len;
4043                }
4044              break;
4045    
4046            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4047            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4048              {              {
# Line 3202  for (;;) Line 4115  for (;;)
4115    
4116          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4117    
4118            if (possessive) continue;
4119          for(;;)          for(;;)
4120            {            {
4121            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
4122            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4123            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4124            BACKCHAR(eptr);            BACKCHAR(eptr);
4125            }            }
4126          }          }
4127        else        else
4128  #endif  #endif  /* SUPPORT_UTF8 */
4129    
4130        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4131          {          {
4132          switch(ctype)          switch(ctype)
4133            {            {
4134            case OP_ANY:            case OP_ANY:
4135            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4136              {              {
4137              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4138                {              eptr++;
               if (eptr >= md->end_subject || *eptr == NEWLINE) break;  
               eptr++;  
               }  
             break;  
4139              }              }
4140            /* For DOTALL case, fall through and treat as \C */            break;
4141    
4142              case OP_ALLANY:
4143            case OP_ANYBYTE:            case OP_ANYBYTE:
4144            c = max - min;            c = max - min;
4145            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
4146                c = md->end_subject - eptr;
4147            eptr += c;            eptr += c;
4148            break;            break;
4149    
4150              case OP_ANYNL:
4151              for (i = min; i < max; i++)
4152                {
4153                if (eptr >= md->end_subject) break;
4154                c = *eptr;
4155                if (c == 0x000d)
4156                  {
4157                  if (++eptr >= md->end_subject) break;
4158                  if (*eptr == 0x000a) eptr++;
4159                  }
4160                else
4161                  {
4162                  if (c != 0x000a &&
4163                      (md->bsr_anycrlf ||
4164                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4165                    break;
4166                  eptr++;
4167                  }
4168                }
4169              break;
4170    
4171              case OP_NOT_HSPACE:
4172              for (i = min; i < max; i++)
4173                {
4174                if (eptr >= md->end_subject) break;
4175                c = *eptr;
4176                if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4177                eptr++;
4178                }
4179              break;
4180    
4181              case OP_HSPACE:
4182              for (i = min; i < max; i++)
4183                {
4184                if (eptr >= md->end_subject) break;
4185                c = *eptr;
4186                if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4187                eptr++;
4188                }
4189              break;
4190    
4191              case OP_NOT_VSPACE:
4192              for (i = min; i < max; i++)
4193                {
4194                if (eptr >= md->end_subject) break;
4195                c = *eptr;
4196                if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4197                  break;
4198                eptr++;
4199                }
4200              break;
4201    
4202              case OP_VSPACE:
4203              for (i = min; i < max; i++)
4204                {
4205                if (eptr >= md->end_subject) break;
4206                c = *eptr;
4207                if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4208                  break;
4209                eptr++;
4210                }
4211              break;
4212    
4213            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4214            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4215              {              {
# Line 3295  for (;;) Line 4270  for (;;)
4270    
4271          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4272    
4273            if (possessive) continue;
4274          while (eptr >= pp)          while (eptr >= pp)
4275            {            {
4276            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
4277            eptr--;            eptr--;
4278            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4279            }            }
# Line 3309  for (;;) Line 4285  for (;;)
4285        }        }
4286      /* Control never gets here */      /* Control never gets here */
4287    
4288      /* There's been some horrible disaster. Since all codes > OP_BRA are      /* There's been some horrible disaster. Arrival here can only mean there is
4289      for capturing brackets, and there shouldn't be any gaps between 0 and      something seriously wrong in the code above or the OP_xxx definitions. */
     OP_BRA, arrival here can only mean there is something seriously wrong  
     in the code above or the OP_xxx definitions. */  
4290    
4291      default:      default:
4292      DPRINTF(("Unknown opcode %d\n", *ecode));      DPRINTF(("Unknown opcode %d\n", *ecode));
4293      RRETURN(PCRE_ERROR_UNKNOWN_NODE);      RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
4294      }      }
4295    
4296    /* Do not stick any code in here without much thought; it is assumed    /* Do not stick any code in here without much thought; it is assumed
# Line 3325  for (;;) Line 4299  for (;;)
4299    
4300    }             /* End of main loop */    }             /* End of main loop */
4301  /* Control never reaches here */  /* Control never reaches here */
4302    
4303    
4304    /* When compiling to use the heap rather than the stack for recursive calls to
4305    match(), the RRETURN() macro jumps here. The number that is saved in
4306    frame->Xwhere indicates which label we actually want to return to. */
4307    
4308    #ifdef NO_RECURSE
4309    #define LBL(val) case val: goto L_RM##val;
4310    HEAP_RETURN:
4311    switch (frame->Xwhere)
4312      {
4313      LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4314      LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4315      LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4316      LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4317      LBL(53) LBL(54)
4318    #ifdef SUPPORT_UTF8
4319      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4320      LBL(32) LBL(34) LBL(42) LBL(46)
4321    #ifdef SUPPORT_UCP
4322      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4323    #endif  /* SUPPORT_UCP */
4324    #endif  /* SUPPORT_UTF8 */
4325      default:
4326      DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4327      return PCRE_ERROR_INTERNAL;
4328      }
4329    #undef LBL
4330    #endif  /* NO_RECURSE */
4331  }  }
4332    
4333    
# Line 3337  Undefine all the macros that were define Line 4340  Undefine all the macros that were define
4340  #ifdef NO_RECURSE  #ifdef NO_RECURSE
4341  #undef eptr  #undef eptr
4342  #undef ecode  #undef ecode
4343    #undef mstart
4344  #undef offset_top  #undef offset_top
4345  #undef ims  #undef ims
4346  #undef eptrb  #undef eptrb
# Line 3354  Undefine all the macros that were define Line 4358  Undefine all the macros that were define
4358    
4359  #undef cur_is_word  #undef cur_is_word
4360  #undef condition  #undef condition
 #undef minimize  
4361  #undef prev_is_word  #undef prev_is_word
4362    
4363  #undef original_ims  #undef original_ims
# Line 3410  Returns:          > 0 => success; value Line 4413  Returns:          > 0 => success; value
4413                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4414  */  */
4415    
4416  PCRE_DATA_SCOPE int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4417  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4418    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4419    int offsetcount)    int offsetcount)
# Line 3419  int rc, resetcount, ocount; Line 4422  int rc, resetcount, ocount;
4422  int first_byte = -1;  int first_byte = -1;
4423  int req_byte = -1;  int req_byte = -1;
4424  int req_byte2 = -1;  int req_byte2 = -1;
4425  unsigned long int ims = 0;  int newline;
4426    unsigned long int ims;
4427  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
4428  BOOL anchored;  BOOL anchored;
4429  BOOL startline;  BOOL startline;
4430  BOOL firstline;  BOOL firstline;
4431  BOOL first_byte_caseless = FALSE;  BOOL first_byte_caseless = FALSE;
4432  BOOL req_byte_caseless = FALSE;  BOOL req_byte_caseless = FALSE;
4433    BOOL utf8;
4434  match_data match_block;  match_data match_block;
4435    match_data *md = &match_block;
4436  const uschar *tables;  const uschar *tables;
4437  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4438  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
# Line 3451  if (offsetcount < 0) return PCRE_ERROR_B Line 4457  if (offsetcount < 0) return PCRE_ERROR_B
4457  the default values. */  the default values. */
4458    
4459  study = NULL;  study = NULL;
4460  match_block.match_limit = MATCH_LIMIT;  md->match_limit = MATCH_LIMIT;
4461  match_block.match_limit_recursion = MATCH_LIMIT_RECURSION;  md->match_limit_recursion = MATCH_LIMIT_RECURSION;
4462  match_block.callout_data = NULL;  md->callout_data = NULL;
4463    
4464  /* The table pointer is always in native byte order. */  /* The table pointer is always in native byte order. */
4465    
# Line 3465  if (extra_data != NULL) Line 4471  if (extra_data != NULL)
4471    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
4472      study = (const pcre_study_data *)extra_data->study_data;      study = (const pcre_study_data *)extra_data->study_data;
4473    if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)    if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)
4474      match_block.match_limit = extra_data->match_limit;      md->match_limit = extra_data->match_limit;
4475    if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)    if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)
4476      match_block.match_limit_recursion = extra_data->match_limit_recursion;      md->match_limit_recursion = extra_data->match_limit_recursion;
4477    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
4478      match_block.callout_data = extra_data->callout_data;      md->callout_data = extra_data->callout_data;
4479    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;
4480    }    }
4481    
# Line 3494  if (re->magic_number != MAGIC_NUMBER) Line 4500  if (re->magic_number != MAGIC_NUMBER)
4500  /* Set up other data */  /* Set up other data */
4501    
4502  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4503  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4504  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4505    
4506  /* The code starts after the real_pcre block and the capture name table. */  /* The code starts after the real_pcre block and the capture name table. */
4507    
4508  match_block.start_code = (const uschar *)external_re + re->name_table_offset +  md->start_code = (const uschar *)external_re + re->name_table_offset +
4509    re->name_count * re->name_entry_size;    re->name_count * re->name_entry_size;
4510    
4511  match_block.start_subject = (USPTR)subject;  md->start_subject = (USPTR)subject;
4512  match_block.start_offset = start_offset;  md->start_offset = start_offset;
4513  match_block.end_subject = match_block.start_subject + length;  md->end_subject = md->start_subject + length;
4514  end_subject = match_block.end_subject;  end_subject = md->end_subject;
4515    
4516  match_block.endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4517  match_block.utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4518    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4519  match_block.notbol = (options & PCRE_NOTBOL) != 0;  
4520  match_block.noteol = (options & PCRE_NOTEOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4521  match_block.notempty = (options & PCRE_NOTEMPTY) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
4522  match_block.partial = (options & PCRE_PARTIAL) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
4523  match_block.hitend = FALSE;  md->partial = (options & PCRE_PARTIAL) != 0;
4524    md->hitend = FALSE;
4525    
4526    md->recursive = NULL;                   /* No recursion at top level */
4527    
4528    md->lcc = tables + lcc_offset;
4529    md->ctypes = tables + ctypes_offset;
4530    
4531    /* Handle different \R options. */
4532    
4533    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4534      {
4535      case 0:
4536      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4537        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4538      else
4539    #ifdef BSR_ANYCRLF
4540      md->bsr_anycrlf = TRUE;
4541    #else
4542      md->bsr_anycrlf = FALSE;
4543    #endif
4544      break;
4545    
4546      case PCRE_BSR_ANYCRLF:
4547      md->bsr_anycrlf = TRUE;
4548      break;
4549    
4550      case PCRE_BSR_UNICODE:
4551      md->bsr_anycrlf = FALSE;
4552      break;
4553    
4554  match_block.recursive = NULL;                   /* No recursion at top level */    default: return PCRE_ERROR_BADNEWLINE;
4555      }
4556    
4557    /* Handle different types of newline. The three bits give eight cases. If
4558    nothing is set at run time, whatever was used at compile time applies. */
4559    
4560  match_block.lcc = tables + lcc_offset;  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4561  match_block.ctypes = tables + ctypes_offset;          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4562      {
4563      case 0: newline = NEWLINE; break;   /* Compile-time default */
4564      case PCRE_NEWLINE_CR: newline = '\r'; break;
4565      case PCRE_NEWLINE_LF: newline = '\n'; break;
4566      case PCRE_NEWLINE_CR+
4567           PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
4568      case PCRE_NEWLINE_ANY: newline = -1; break;
4569      case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4570      default: return PCRE_ERROR_BADNEWLINE;
4571      }
4572    
4573    if (newline == -2)
4574      {
4575      md->nltype = NLTYPE_ANYCRLF;
4576      }
4577    else if (newline < 0)
4578      {
4579      md->nltype = NLTYPE_ANY;
4580      }
4581    else
4582      {
4583      md->nltype = NLTYPE_FIXED;
4584      if (newline > 255)
4585        {
4586        md->nllen = 2;
4587        md->nl[0] = (newline >> 8) & 255;
4588        md->nl[1] = newline & 255;
4589        }
4590      else
4591        {
4592        md->nllen = 1;
4593        md->nl[0] = newline;
4594        }
4595      }
4596    
4597  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching is supported only for a restricted set of regexes at the
4598  moment. */  moment. */
4599    
4600  if (match_block.partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4601    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4602    
4603  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Unfortunately there's no way of passing
4604  back the character offset. */  back the character offset. */
4605    
4606  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4607  if (match_block.utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
4608    {    {
4609    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)
4610      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
# Line 3563  ocount = offsetcount - (offsetcount % 3) Line 4636  ocount = offsetcount - (offsetcount % 3)
4636  if (re->top_backref > 0 && re->top_backref >= ocount/3)  if (re->top_backref > 0 && re->top_backref >= ocount/3)
4637    {    {
4638    ocount = re->top_backref * 3 + 3;    ocount = re->top_backref * 3 + 3;
4639    match_block.offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));    md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
4640    if (match_block.offset_vector == NULL) return PCRE_ERROR_NOMEMORY;    if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
4641    using_temporary_offsets = TRUE;    using_temporary_offsets = TRUE;
4642    DPRINTF(("Got memory to hold back references\n"));    DPRINTF(("Got memory to hold back references\n"));
4643    }    }
4644  else match_block.offset_vector = offsets;  else md->offset_vector = offsets;
4645    
4646  match_block.offset_end = ocount;  md->offset_end = ocount;
4647  match_block.offset_max = (2*ocount)/3;  md->offset_max = (2*ocount)/3;
4648  match_block.offset_overflow = FALSE;  md->offset_overflow = FALSE;
4649  match_block.capture_last = -1;  md->capture_last = -1;
4650    
4651  /* Compute the minimum number of offsets that we need to reset each time. Doing  /* Compute the minimum number of offsets that we need to reset each time. Doing
4652  this makes a huge difference to execution time when there aren't many brackets  this makes a huge difference to execution time when there aren't many brackets
# Line 3586  if (resetcount > offsetcount) resetcount Line 4659  if (resetcount > offsetcount) resetcount
4659  never be used unless previously set, but they get saved and restored, and so we  never be used unless previously set, but they get saved and restored, and so we
4660  initialize them to avoid reading uninitialized locations. */  initialize them to avoid reading uninitialized locations. */
4661    
4662  if (match_block.offset_vector != NULL)  if (md->offset_vector != NULL)
4663    {    {
4664    register int *iptr = match_block.offset_vector + ocount;    register int *iptr = md->offset_vector + ocount;
4665    register int *iend = iptr - resetcount/2 + 1;    register int *iend = iptr - resetcount/2 + 1;
4666    while (--iptr >= iend) *iptr = -1;    while (--iptr >= iend) *iptr = -1;
4667    }    }
# Line 3601  studied, there may be a bitmap of possib Line 4674  studied, there may be a bitmap of possib
4674    
4675  if (!anchored)  if (!anchored)
4676    {    {
4677    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4678      {      {
4679      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4680      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
4681        first_byte = match_block.lcc[first_byte];        first_byte = md->lcc[first_byte];
4682      }      }
4683    else    else
4684      if (!startline && study != NULL &&      if (!startline && study != NULL &&
# Line 3616  if (!anchored) Line 4689  if (!anchored)
4689  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4690  character" set. */  character" set. */
4691    
4692  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4693    {    {
4694    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4695    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
4696    req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */    req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */
4697    }    }
4698    
4699    
4700    /* ==========================================================================*/
4701    
4702  /* Loop for handling unanchored repeated matching attempts; for anchored regexs  /* Loop for handling unanchored repeated matching attempts; for anchored regexs
4703  the loop runs just once. */  the loop runs just once. */
4704    
4705  do  for(;;)
4706    {    {
4707    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
4708      USPTR new_start_match;
4709    
4710    /* Reset the maximum number of extractions we might see. */    /* Reset the maximum number of extractions we might see. */
4711    
4712    if (match_block.offset_vector != NULL)    if (md->offset_vector != NULL)
4713      {      {
4714      register int *iptr = match_block.offset_vector;      register int *iptr = md->offset_vector;
4715      register int *iend = iptr + resetcount;      register int *iend = iptr + resetcount;
4716      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
4717      }      }
4718    
4719    /* Advance to a unique first char if possible. If firstline is TRUE, the    /* Advance to a unique first char if possible. If firstline is TRUE, the
4720    start of the match is constrained to the first line of a multiline string.    start of the match is constrained to the first line of a multiline string.
4721    Implement this by temporarily adjusting end_subject so that we stop scanning    That is, the match must be before or at the first newline. Implement this by
4722    at a newline. If the match fails at the newline, later code breaks this loop.    temporarily adjusting end_subject so that we stop scanning at a newline. If
4723    */    the match fails at the newline, later code breaks this loop. */
4724    
4725    if (firstline)    if (firstline)
4726      {      {
4727      USPTR t = start_match;      USPTR t = start_match;
4728      while (t < save_end_subject && *t != '\n') t++;  #ifdef SUPPORT_UTF8
4729        if (utf8)
4730          {
4731          while (t < md->end_subject && !IS_NEWLINE(t))
4732            {
4733            t++;
4734            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4735            }
4736          }
4737        else
4738    #endif
4739        while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4740      end_subject = t;      end_subject = t;
4741      }      }
4742    
4743    /* Now test for a unique first byte */    /* Now advance to a unique first byte if there is one. */
4744    
4745    if (first_byte >= 0)    if (first_byte >= 0)
4746      {      {
4747      if (first_byte_caseless)      if (first_byte_caseless)
4748        while (start_match < end_subject &&        while (start_match < end_subject && md->lcc[*start_match] != first_byte)
              match_block.lcc[*start_match] != first_byte)  
4749          start_match++;          start_match++;
4750      else      else
4751        while (start_match < end_subject && *start_match != first_byte)        while (start_match < end_subject && *start_match != first_byte)
4752          start_match++;          start_match++;
4753      }      }
4754    
4755    /* Or to just after \n for a multiline match if possible */    /* Or to just after a linebreak for a multiline match */
4756    
4757    else if (startline)    else if (startline)
4758      {      {
4759      if (start_match > match_block.start_subject + start_offset)      if (start_match > md->start_subject + start_offset)
4760        {        {
4761        while (start_match < end_subject && start_match[-1] != NEWLINE)  #ifdef SUPPORT_UTF8
4762          if (utf8)
4763            {
4764            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4765              {
4766              start_match++;
4767              while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4768                start_match++;
4769              }
4770            }
4771          else
4772    #endif
4773          while (start_match < end_subject && !WAS_NEWLINE(start_match))
4774            start_match++;
4775    
4776          /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
4777          and we are now at a LF, advance the match position by one more character.
4778          */
4779    
4780          if (start_match[-1] == '\r' &&
4781               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4782               start_match < end_subject &&
4783               *start_match == '\n')
4784          start_match++;          start_match++;
4785        }        }
4786      }      }
4787    
4788    /* Or to a non-unique first char after study */    /* Or to a non-unique first byte after study */
4789    
4790    else if (start_bits != NULL)    else if (start_bits != NULL)
4791      {      {
4792      while (start_match < end_subject)      while (start_match < end_subject)
4793        {        {
4794        register unsigned int c = *start_match;        register unsigned int c = *start_match;
4795        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
4796            else break;
4797        }        }
4798      }      }
4799    
# Line 3693  do Line 4803  do
4803    
4804  #ifdef DEBUG  /* Sigh. Some compilers never learn. */  #ifdef DEBUG  /* Sigh. Some compilers never learn. */
4805    printf(">>>> Match against: ");    printf(">>>> Match against: ");
4806    pchars(start_match, end_subject - start_match, TRUE, &match_block);    pchars(start_match, end_subject - start_match, TRUE, md);
4807    printf("\n");    printf("\n");
4808  #endif  #endif
4809    
# Line 3707  do Line 4817  do
4817    
4818    HOWEVER: when the subject string is very, very long, searching to its end can    HOWEVER: when the subject string is very, very long, searching to its end can
4819    take a long time, and give bad performance on quite ordinary patterns. This    take a long time, and give bad performance on quite ordinary patterns. This
4820    showed up when somebody was matching /^C/ on a 32-megabyte string... so we    showed up when somebody was matching something like /^\d+C/ on a 32-megabyte
4821    don't do this when the string is sufficiently long.    string... so we don't do this when the string is sufficiently long.
4822    
4823    ALSO: this processing is disabled when partial matching is requested.    ALSO: this processing is disabled when partial matching is requested.
4824    */    */
4825    
4826    if (req_byte >= 0 &&    if (req_byte >= 0 &&
4827        end_subject - start_match < REQ_BYTE_MAX &&        end_subject - start_match < REQ_BYTE_MAX &&
4828        !match_block.partial)        !md->partial)
4829      {      {
4830      register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);      register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
4831    
# Line 3740  do Line 4850  do
4850            }            }
4851          }          }
4852    
4853        /* If we can't find the required character, break the matching loop */        /* If we can't find the required character, break the matching loop,
4854          forcing a match failure. */
4855    
4856        if (p >= end_subject) break;        if (p >= end_subject)
4857            {
4858            rc = MATCH_NOMATCH;
4859            break;
4860            }
4861    
4862        /* If we have found the required character, save the point where we        /* If we have found the required character, save the point where we
4863        found it, so that we don't search again next time round the loop if        found it, so that we don't search again next time round the loop if
# Line 3752  do Line 4867  do
4867        }        }
4868      }      }
4869    
4870    /* When a match occurs, substrings will be set for all internal extractions;    /* OK, we can now run the match. */
4871    we just need to set up the whole thing as substring 0 before returning. If  
4872