/[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 446 by ph10, Tue Sep 15 10:49:50 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 269  typedef struct heapframe { Line 322  typedef struct heapframe {
322    
323    /* Function arguments that may change */    /* Function arguments that may change */
324    
325    const uschar *Xeptr;    USPTR Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      USPTR 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    
336    const uschar *Xcallpat;    USPTR Xcallpat;
337    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
338    const uschar *Xdata;    USPTR Xcharptr;
339    const uschar *Xnext;  #endif
340    const uschar *Xpp;    USPTR Xdata;
341    const uschar *Xprev;    USPTR Xnext;
342    const uschar *Xsaved_eptr;    USPTR Xpp;
343      USPTR Xprev;
344      USPTR Xsaved_eptr;
345    
346    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
347    
348    BOOL Xcur_is_word;    BOOL Xcur_is_word;
349    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
350    BOOL Xprev_is_word;    BOOL Xprev_is_word;
351    
352    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 358  typedef struct heapframe {
358    int Xprop_category;    int Xprop_category;
359    int Xprop_chartype;    int Xprop_chartype;
360    int Xprop_script;    int Xprop_script;
361    int *Xprop_test_variable;    int Xoclength;
362      uschar Xocchars[8];
363  #endif  #endif
364    
365      int Xcodelink;
366    int Xctype;    int Xctype;
367    int Xfc;    unsigned int Xfc;
368    int Xfi;    int Xfi;
369    int Xlength;    int Xlength;
370    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 378  typedef struct heapframe {
378    
379    eptrblock Xnewptrb;    eptrblock Xnewptrb;
380    
381    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
382    
383    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
384    
385  } heapframe;  } heapframe;
386    
# Line 340  typedef struct heapframe { Line 396  typedef struct heapframe {
396  *         Match from current position            *  *         Match from current position            *
397  *************************************************/  *************************************************/
398    
399  /* 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  
400  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
401  same response.  same response. */
402    
403    /* These macros pack up tests that are used for partial matching, and which
404    appears several times in the code. We set the "hit end" flag if the pointer is
405    at the end of the subject and also past the start of the subject (i.e.
406    something has been matched). For hard partial matching, we then return
407    immediately. The second one is used when we already know we are past the end of
408    the subject. */
409    
410    #define CHECK_PARTIAL()\
411      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
412        {\
413        md->hitend = TRUE;\
414        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415        }
416    
417  Performance note: It might be tempting to extract commonly used fields from the  #define SCHECK_PARTIAL()\
418  md structure (e.g. utf8, end_subject) into individual variables to improve    if (md->partial && eptr > mstart)\
419        {\
420        md->hitend = TRUE;\
421        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422        }
423    
424    
425    /* Performance note: It might be tempting to extract commonly used fields from
426    the md structure (e.g. utf8, end_subject) into individual variables to improve
427  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
428  made performance worse.  made performance worse.
429    
430  Arguments:  Arguments:
431     eptr        pointer in subject     eptr        pointer to current character in subject
432     ecode       position in code     ecode       pointer to current position in compiled code
433       mstart      pointer to the current match start position (can be modified
434                     by encountering \K)
435     offset_top  current top pointer     offset_top  current top pointer
436     md          pointer to "static" info for the match     md          pointer to "static" info for the match
437     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 439  Arguments:
439                   brackets - for testing for empty matches                   brackets - for testing for empty matches
440     flags       can contain     flags       can contain
441                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
442                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
443                       group that can match an empty string
444     rdepth      the recursion depth     rdepth      the recursion depth
445    
446  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 450  Returns:       MATCH_MATCH if matched
450  */  */
451    
452  static int  static int
453  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
454    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
455    int flags, int rdepth)    int flags, unsigned int rdepth)
456  {  {
457  /* 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,
458  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
459  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
460    
461  register int  rrc;    /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
462  register int  i;      /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
463  register int  c;      /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
464  register BOOL utf8;   /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
465    
466    BOOL minimize, possessive; /* Quantifier options */
467    int condcode;
468    
469  /* 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
470  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 479  frame->Xprevframe = NULL;            /*
479    
480  frame->Xeptr = eptr;  frame->Xeptr = eptr;
481  frame->Xecode = ecode;  frame->Xecode = ecode;
482    frame->Xmstart = mstart;
483  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
484  frame->Xims = ims;  frame->Xims = ims;
485  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 494  HEAP_RECURSE:
494    
495  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
496  #define ecode              frame->Xecode  #define ecode              frame->Xecode
497    #define mstart             frame->Xmstart
498  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
499  #define ims                frame->Xims  #define ims                frame->Xims
500  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 424  HEAP_RECURSE: Line 507  HEAP_RECURSE:
507  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
508  #endif  #endif
509  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
510    #define codelink           frame->Xcodelink
511  #define data               frame->Xdata  #define data               frame->Xdata
512  #define next               frame->Xnext  #define next               frame->Xnext
513  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 434  HEAP_RECURSE: Line 518  HEAP_RECURSE:
518    
519  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
520  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
521  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
522    
523  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 529  HEAP_RECURSE:
529  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
530  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
531  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
532  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
533    #define occhars            frame->Xocchars
534  #endif  #endif
535    
536  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 554  HEAP_RECURSE:
554  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
555  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
556    
557  #else  #else         /* NO_RECURSE not defined */
558  #define fi i  #define fi i
559  #define fc c  #define fc c
560    
# Line 489  recursion_info new_recursive;      /* wi Line 573  recursion_info new_recursive;      /* wi
573                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
574  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
575  BOOL condition;  BOOL condition;
 BOOL minimize;  
576  BOOL prev_is_word;  BOOL prev_is_word;
577    
578  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 584  int prop_fail_result;
584  int prop_category;  int prop_category;
585  int prop_chartype;  int prop_chartype;
586  int prop_script;  int prop_script;
587  int *prop_test_variable;  int oclength;
588    uschar occhars[8];
589  #endif  #endif
590    
591    int codelink;
592  int ctype;  int ctype;
593  int length;  int length;
594  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 601  int save_offset1, save_offset2, save_off
601  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
602    
603  eptrblock newptrb;  eptrblock newptrb;
604  #endif  #endif     /* NO_RECURSE */
605    
606  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
607  variables. */  variables. */
# Line 524  variables. */ Line 609  variables. */
609  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
610  prop_value = 0;  prop_value = 0;
611  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
612  #endif  #endif
613    
614    
615    /* This label is used for tail recursion, which is used in a few cases even
616    when NO_RECURSE is not defined, in order to reduce the amount of stack that is
617    used. Thanks to Ian Taylor for noticing this possibility and sending the
618    original patch. */
619    
620    TAIL_RECURSE:
621    
622  /* 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
623  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
624  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 627  defined). However, RMATCH isn't like a f
627  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,
628  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
629    
630    #ifdef SUPPORT_UTF8
631    utf8 = md->utf8;       /* Local copy of the flag */
632    #else
633    utf8 = FALSE;
634    #endif
635    
636  /* 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
637  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
638    
# Line 542  if (md->match_call_count++ >= md->match_ Line 640  if (md->match_call_count++ >= md->match_
640  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
641    
642  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
 utf8 = md->utf8;       /* Local copy of the flag */  
643    
644  /* 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
645  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
646  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
647  this stack. */  hit the closing ket, in order to break infinite loops that match no characters.
648    When match() is called in other circumstances, don't add to the chain. The
649    match_cbegroup flag must NOT be used with tail recursion, because the memory
650    block that is used is on the stack, so a new one may be required for each
651    match(). */
652    
653  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
654    {    {
   newptrb.epb_prev = eptrb;  
655    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
656      newptrb.epb_prev = eptrb;
657    eptrb = &newptrb;    eptrb = &newptrb;
658    }    }
659    
660  /* Now start processing the operations. */  /* Now start processing the opcodes. */
661    
662  for (;;)  for (;;)
663    {    {
664      minimize = possessive = FALSE;
665    op = *ecode;    op = *ecode;
   minimize = FALSE;  
   
   /* For partial matching, remember if we ever hit the end of the subject after  
   matching at least one subject character. */  
   
   if (md->partial &&  
       eptr >= md->end_subject &&  
       eptr > md->start_match)  
     md->hitend = TRUE;  
   
   /* Opening capturing bracket. If there is space in the offset vector, save  
   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. */  
666    
667    if (op > OP_BRA)    switch(op)
668      {      {
669      number = op - OP_BRA;      case OP_FAIL:
670        RRETURN(MATCH_NOMATCH);
     /* For extended extraction brackets (large number), we have to fish out the  
     number from a dummy opcode at the start. */  
671    
672      if (number > EXTRACT_BASIC_MAX)      case OP_PRUNE:
673        number = GET2(ecode, 2+LINK_SIZE);      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
674          ims, eptrb, flags, RM51);
675        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
676        RRETURN(MATCH_PRUNE);
677    
678        case OP_COMMIT:
679        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
680          ims, eptrb, flags, RM52);
681        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
682        RRETURN(MATCH_COMMIT);
683    
684        case OP_SKIP:
685        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
686          ims, eptrb, flags, RM53);
687        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
688        md->start_match_ptr = eptr;   /* Pass back current position */
689        RRETURN(MATCH_SKIP);
690    
691        case OP_THEN:
692        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
693          ims, eptrb, flags, RM54);
694        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
695        RRETURN(MATCH_THEN);
696    
697        /* Handle a capturing bracket. If there is space in the offset vector, save
698        the current subject position in the working slot at the top of the vector.
699        We mustn't change the current values of the data slot, because they may be
700        set from a previous iteration of this group, and be referred to by a
701        reference inside the group.
702    
703        If the bracket fails to match, we need to restore this value and also the
704        values of the final offsets, in case they were set by a previous iteration
705        of the same bracket.
706    
707        If there isn't enough space in the offset vector, treat this as if it were
708        a non-capturing bracket. Don't worry about setting the flag for the error
709        case here; that is handled in the code for KET. */
710    
711        case OP_CBRA:
712        case OP_SCBRA:
713        number = GET2(ecode, 1+LINK_SIZE);
714      offset = number << 1;      offset = number << 1;
715    
716  #ifdef DEBUG  #ifdef DEBUG
717      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
718        printf("subject=");
719      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
720      printf("\n");      printf("\n");
721  #endif  #endif
# Line 612  for (;;) Line 730  for (;;)
730        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
731        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
732    
733          flags = (op == OP_SCBRA)? match_cbegroup : 0;
734        do        do
735          {          {
736          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
737            match_isgroup);            ims, eptrb, flags, RM1);
738          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
739          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
740          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
741          }          }
# Line 631  for (;;) Line 750  for (;;)
750        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
751        }        }
752    
753      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
754        as a non-capturing bracket. */
755    
756      else op = OP_BRA;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
757      }      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
758    
759    /* Other types of node can be handled by a switch */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
760    
761    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
762      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
763      case OP_BRA:     /* Non-capturing bracket: optimized */  
764      DPRINTF(("start bracket 0\n"));      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
765      do      final alternative within the brackets, we would return the result of a
766        recursive call to match() whatever happened. We can reduce stack usage by
767        turning this into a tail recursion, except in the case when match_cbegroup
768        is set.*/
769    
770        case OP_BRA:
771        case OP_SBRA:
772        DPRINTF(("start non-capturing bracket\n"));
773        flags = (op >= OP_SBRA)? match_cbegroup : 0;
774        for (;;)
775        {        {
776        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
777          match_isgroup);          {
778        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (flags == 0)    /* Not a possibly empty group */
779              {
780              ecode += _pcre_OP_lengths[*ecode];
781              DPRINTF(("bracket 0 tail recursion\n"));
782              goto TAIL_RECURSE;
783              }
784    
785            /* Possibly empty group; can't use tail recursion. */
786    
787            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
788              eptrb, flags, RM48);
789            RRETURN(rrc);
790            }
791    
792          /* For non-final alternatives, continue the loop for a NOMATCH result;
793          otherwise return. */
794    
795          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
796            eptrb, flags, RM2);
797          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
798        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
799        }        }
800      while (*ecode == OP_ALT);      /* Control never reaches here. */
     DPRINTF(("bracket 0 failed\n"));  
     RRETURN(MATCH_NOMATCH);  
801    
802      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
803      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
804      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
805      exactly what going to the ket would do. */      exactly what going to the ket would do. As there is only one branch to be
806        obeyed, we can use tail recursion to avoid using another stack frame. */
807    
808      case OP_COND:      case OP_COND:
809      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
810        codelink= GET(ecode, 1);
811    
812        /* Because of the way auto-callout works during compile, a callout item is
813        inserted between OP_COND and an assertion condition. */
814    
815        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
816          {
817          if (pcre_callout != NULL)
818            {
819            pcre_callout_block cb;
820            cb.version          = 1;   /* Version 1 of the callout block */
821            cb.callout_number   = ecode[LINK_SIZE+2];
822            cb.offset_vector    = md->offset_vector;
823            cb.subject          = (PCRE_SPTR)md->start_subject;
824            cb.subject_length   = md->end_subject - md->start_subject;
825            cb.start_match      = mstart - md->start_subject;
826            cb.current_position = eptr - md->start_subject;
827            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
828            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
829            cb.capture_top      = offset_top/2;
830            cb.capture_last     = md->capture_last;
831            cb.callout_data     = md->callout_data;
832            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
833            if (rrc < 0) RRETURN(rrc);
834            }
835          ecode += _pcre_OP_lengths[OP_CALLOUT];
836          }
837    
838        condcode = ecode[LINK_SIZE+1];
839    
840        /* Now see what the actual condition is */
841    
842        if (condcode == OP_RREF)         /* Recursion test */
843          {
844          offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
845          condition = md->recursive != NULL &&
846            (offset == RREF_ANY || offset == md->recursive->group_num);
847          ecode += condition? 3 : GET(ecode, 1);
848          }
849    
850        else if (condcode == OP_CREF)    /* Group used test */
851        {        {
852        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
853        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
854          (md->recursive != NULL) :        ecode += condition? 3 : GET(ecode, 1);
855          (offset < offset_top && md->offset_vector[offset] >= 0);        }
856        RMATCH(rrc, eptr, ecode + (condition?  
857          (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))),      else if (condcode == OP_DEF)     /* DEFINE - always false */
858          offset_top, md, ims, eptrb, match_isgroup);        {
859        RRETURN(rrc);        condition = FALSE;
860          ecode += GET(ecode, 1);
861        }        }
862    
863      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
864      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
865        assertion. */
866    
867      else      else
868        {        {
869        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
870            match_condassert | match_isgroup);            match_condassert, RM3);
871        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
872          {          {
873          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
874            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
875          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
876          }          }
877        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
878          {          {
879          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
880          }          }
881        else ecode += GET(ecode, 1);        else
882        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          {
883          match_isgroup);          condition = FALSE;
884        RRETURN(rrc);          ecode += codelink;
885            }
886        }        }
     /* Control never reaches here */  
887    
888      /* 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,
889      encountered. */      we can use tail recursion to avoid using another stack frame, except when
890        match_cbegroup is required for an unlimited repeat of a possibly empty
891        group. If the second alternative doesn't exist, we can just plough on. */
892    
893      case OP_CREF:      if (condition || *ecode == OP_ALT)
894      case OP_BRANUMBER:        {
895      ecode += 3;        ecode += 1 + LINK_SIZE;
896          if (op == OP_SCOND)        /* Possibly empty group */
897            {
898            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
899            RRETURN(rrc);
900            }
901          else                       /* Group must match something */
902            {
903            flags = 0;
904            goto TAIL_RECURSE;
905            }
906          }
907        else                         /* Condition false & no alternative */
908          {
909          ecode += 1 + LINK_SIZE;
910          }
911      break;      break;
912    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
913    
914        /* End of the pattern, either real or forced. If we are in a top-level
915        recursion, we should restore the offsets appropriately and continue from
916        after the call. */
917    
918        case OP_ACCEPT:
919      case OP_END:      case OP_END:
920      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
921        {        {
# Line 713  for (;;) Line 924  for (;;)
924        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
925        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
926          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
927        md->start_match = rec->save_start;        offset_top = rec->offset_top;
928          mstart = rec->save_start;
929        ims = original_ims;        ims = original_ims;
930        ecode = rec->after_call;        ecode = rec->after_call;
931        break;        break;
932        }        }
933    
934      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
935      string - backtracking will then try other alternatives, if any. */      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
936        the subject. In both cases, backtracking will then try other alternatives,
937        if any. */
938    
939        if (eptr == mstart &&
940            (md->notempty ||
941              (md->notempty_atstart &&
942                mstart == md->start_subject + md->start_offset)))
943          RRETURN(MATCH_NOMATCH);
944    
945        /* Otherwise, we have a match. */
946    
947      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      md->end_match_ptr = eptr;           /* Record where we ended */
948      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
949      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
950      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
951    
952      /* Change option settings */      /* Change option settings */
# Line 745  for (;;) Line 967  for (;;)
967      case OP_ASSERTBACK:      case OP_ASSERTBACK:
968      do      do
969        {        {
970        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
971          match_isgroup);          RM4);
972        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
973        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
974        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
975        }        }
976      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 772  for (;;) Line 994  for (;;)
994      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
995      do      do
996        {        {
997        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
998          match_isgroup);          RM5);
999        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
1000        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1001        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1002        }        }
1003      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 794  for (;;) Line 1016  for (;;)
1016  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1017      if (utf8)      if (utf8)
1018        {        {
1019        c = GET(ecode,1);        i = GET(ecode, 1);
1020        for (i = 0; i < c; i++)        while (i-- > 0)
1021          {          {
1022          eptr--;          eptr--;
1023          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1024          BACKCHAR(eptr)          BACKCHAR(eptr);
1025          }          }
1026        }        }
1027      else      else
# Line 808  for (;;) Line 1030  for (;;)
1030      /* 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 */
1031    
1032        {        {
1033        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1034        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1035        }        }
1036    
1037      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1038    
1039        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1040      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1041      break;      break;
1042    
# Line 830  for (;;) Line 1053  for (;;)
1053        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1054        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1055        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1056        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1057        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1058        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1059        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 865  for (;;) Line 1088  for (;;)
1088      case OP_RECURSE:      case OP_RECURSE:
1089        {        {
1090        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1091        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1092            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);  
1093    
1094        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1095    
# Line 897  for (;;) Line 1115  for (;;)
1115    
1116        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1117              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1118        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1119        md->start_match = eptr;        new_recursive.offset_top = offset_top;
1120          mstart = eptr;
1121    
1122        /* 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
1123        restore the offset and recursion data. */        restore the offset and recursion data. */
1124    
1125        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1126          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1127        do        do
1128          {          {
1129          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1130              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1131          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1132            {            {
1133            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 916  for (;;) Line 1136  for (;;)
1136              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1137            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1138            }            }
1139          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1140            {            {
1141            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1142              if (new_recursive.offset_save != stacksave)
1143                (pcre_free)(new_recursive.offset_save);
1144            RRETURN(rrc);            RRETURN(rrc);
1145            }            }
1146    
# Line 945  for (;;) Line 1167  for (;;)
1167      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer. */
1168    
1169      case OP_ONCE:      case OP_ONCE:
1170        {      prev = ecode;
1171        prev = ecode;      saved_eptr = eptr;
       saved_eptr = eptr;  
1172    
1173        do      do
1174          {        {
1175          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1176            eptrb, match_isgroup);        if (rrc == MATCH_MATCH) break;
1177          if (rrc == MATCH_MATCH) break;        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1178          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        ecode += GET(ecode,1);
1179          ecode += GET(ecode,1);        }
1180          }      while (*ecode == OP_ALT);
       while (*ecode == OP_ALT);  
1181    
1182        /* If hit the end of the group (which could be repeated), fail */      /* If hit the end of the group (which could be repeated), fail */
1183    
1184        if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1185    
1186        /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1187        mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1188    
1189        do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1190    
1191        offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1192        eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
1193    
1194        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1195        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.
1196        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1197        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
1198        course of events. */      course of events. */
1199    
1200        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1201          {        {
1202          ecode += 1+LINK_SIZE;        ecode += 1+LINK_SIZE;
1203          break;        break;
1204          }        }
1205    
1206        /* 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
1207        preceding bracket, in the appropriate order. We need to reset any options      preceding bracket, in the appropriate order. The second "call" of match()
1208        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
1209        opcode. */      any options that changed within the bracket before re-running it, so
1210        check the next opcode. */
1211    
1212        if (ecode[1+LINK_SIZE] == OP_OPT)      if (ecode[1+LINK_SIZE] == OP_OPT)
1213          {        {
1214          ims = (ims & ~PCRE_IMS) | ecode[4];        ims = (ims & ~PCRE_IMS) | ecode[4];
1215          DPRINTF(("ims set to %02lx at group repeat\n", ims));        DPRINTF(("ims set to %02lx at group repeat\n", ims));
1216          }        }
1217    
1218        if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1219          {        {
1220          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);
1221          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1222          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        ecode = prev;
1223          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        flags = 0;
1224          }        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);  
         }  
1225        }        }
1226      RRETURN(MATCH_NOMATCH);      else  /* OP_KETRMAX */
1227          {
1228          RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1229          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1230          ecode += 1 + LINK_SIZE;
1231          flags = 0;
1232          goto TAIL_RECURSE;
1233          }
1234        /* Control never gets here */
1235    
1236      /* 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
1237      bracketed group and go to there. */      bracketed group and go to there. */
# Line 1018  for (;;) Line 1240  for (;;)
1240      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1241      break;      break;
1242    
1243      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1244      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
1245      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
1246      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
1247      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1248    
1249      case OP_BRAZERO:      case OP_BRAZERO:
1250        {        {
1251        next = ecode+1;        next = ecode+1;
1252        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1253        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1254        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1255        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1256        }        }
1257      break;      break;
1258    
1259      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1260        {        {
1261        next = ecode+1;        next = ecode+1;
1262        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1263        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);  
1264        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1265        ecode++;        ecode++;
1266        }        }
1267      break;      break;
1268    
1269      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1270      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1271      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1272      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1273          ecode = next + 1 + LINK_SIZE;
1274          }
1275        break;
1276    
1277        /* End of a group, repeated or non-repeating. */
1278    
1279      case OP_KET:      case OP_KET:
1280      case OP_KETRMIN:      case OP_KETRMIN:
1281      case OP_KETRMAX:      case OP_KETRMAX:
1282        {      prev = ecode - GET(ecode, 1);
       prev = ecode - GET(ecode, 1);  
       saved_eptr = eptrb->epb_saved_eptr;  
   
       /* Back up the stack of bracket start pointers. */  
   
       eptrb = eptrb->epb_prev;  
1283    
1284        if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      /* If this was a group that remembered the subject start, in order to break
1285            *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||      infinite repeats of empty string matches, retrieve the subject start from
1286            *prev == OP_ONCE)      the chain. Otherwise, set it NULL. */
         {  
         md->end_match_ptr = eptr;      /* For ONCE */  
         md->end_offset_top = offset_top;  
         RRETURN(MATCH_MATCH);  
         }  
1287    
1288        /* In all other cases except a conditional group we have to check the      if (*prev >= OP_SBRA)
1289        group number back at the start and if necessary complete handling an        {
1290        extraction by setting the offsets and bumping the high water mark. */        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1291          eptrb = eptrb->epb_prev;              /* Backup to previous group */
1292          }
1293        else saved_eptr = NULL;
1294    
1295        if (*prev != OP_COND)      /* If we are at the end of an assertion group, stop matching and return
1296          {      MATCH_MATCH, but record the current high water mark for use by positive
1297          number = *prev - OP_BRA;      assertions. Do this also for the "once" (atomic) groups. */
1298    
1299          /* For extended extraction brackets (large number), we have to fish out      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1300          the number from a dummy opcode at the start. */          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1301            *prev == OP_ONCE)
1302          {
1303          md->end_match_ptr = eptr;      /* For ONCE */
1304          md->end_offset_top = offset_top;
1305          RRETURN(MATCH_MATCH);
1306          }
1307    
1308          if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);      /* For capturing groups we have to check the group number back at the start
1309          offset = number << 1;      and if necessary complete handling an extraction by setting the offsets and
1310        bumping the high water mark. Note that whole-pattern recursion is coded as
1311        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1312        when the OP_END is reached. Other recursion is handled here. */
1313    
1314        if (*prev == OP_CBRA || *prev == OP_SCBRA)
1315          {
1316          number = GET2(prev, 1+LINK_SIZE);
1317          offset = number << 1;
1318    
1319  #ifdef DEBUG  #ifdef DEBUG
1320          printf("end bracket %d", number);        printf("end bracket %d", number);
1321          printf("\n");        printf("\n");
1322  #endif  #endif
1323    
1324          /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1325          of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1326          into group 0, so it won't be picked up here. Instead, we catch it when          {
1327          the OP_END is reached. */          md->offset_vector[offset] =
1328              md->offset_vector[md->offset_end - number];
1329          if (number > 0)          md->offset_vector[offset+1] = eptr - md->start_subject;
1330            {          if (offset_top <= offset) offset_top = offset + 2;
1331            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;  
             }  
1332    
1333            /* Handle a recursively called group. Restore the offsets        /* Handle a recursively called group. Restore the offsets
1334            appropriately and continue from after the call. */        appropriately and continue from after the call. */
1335    
1336            if (md->recursive != NULL && md->recursive->group_num == number)        if (md->recursive != NULL && md->recursive->group_num == number)
1337              {          {
1338              recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1339              DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1340              md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
1341              md->start_match = rec->save_start;          mstart = rec->save_start;
1342              memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1343                rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1344              ecode = rec->after_call;          offset_top = rec->offset_top;
1345              ims = original_ims;          ecode = rec->after_call;
1346              break;          ims = original_ims;
1347              }          break;
           }  
1348          }          }
1349          }
1350    
1351        /* 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
1352        the group. */      flags, in case they got changed during the group. */
1353    
1354        ims = original_ims;      ims = original_ims;
1355        DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
1356    
1357        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1358        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.
1359        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1360        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
1361        course of events. */      course of events. */
1362    
1363        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1364          {        {
1365          ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1366          break;        break;
1367          }        }
1368    
1369        /* 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
1370        preceding bracket, in the appropriate order. */      preceding bracket, in the appropriate order. In the second case, we can use
1371        tail recursion to avoid using another stack frame, unless we have an
1372        unlimited repeat of a group that can match an empty string. */
1373    
1374        if (*ecode == OP_KETRMIN)      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1375          {  
1376          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);      if (*ecode == OP_KETRMIN)
1377          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        {
1378          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1379          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1380          }        if (flags != 0)    /* Could match an empty string */
       else  /* OP_KETRMAX */  
1381          {          {
1382          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1383          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);  
1384          }          }
1385          ecode = prev;
1386          goto TAIL_RECURSE;
1387        }        }
1388        else  /* OP_KETRMAX */
1389      RRETURN(MATCH_NOMATCH);        {
1390          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1391          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1392          ecode += 1 + LINK_SIZE;
1393          flags = 0;
1394          goto TAIL_RECURSE;
1395          }
1396        /* Control never gets here */
1397    
1398      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1399    
# Line 1168  for (;;) Line 1401  for (;;)
1401      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1402      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1403        {        {
1404        if (eptr != md->start_subject && eptr[-1] != NEWLINE)        if (eptr != md->start_subject &&
1405              (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1406          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1407        ecode++;        ecode++;
1408        break;        break;
# Line 1189  for (;;) Line 1423  for (;;)
1423      ecode++;      ecode++;
1424      break;      break;
1425    
1426        /* Reset the start of match point */
1427    
1428        case OP_SET_SOM:
1429        mstart = eptr;
1430        ecode++;
1431        break;
1432    
1433      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1434      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. */
1435    
# Line 1196  for (;;) Line 1437  for (;;)
1437      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1438        {        {
1439        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1440          { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
1441        else        else
1442          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) RRETURN(MATCH_NOMATCH); }
1443        ecode++;        ecode++;
# Line 1207  for (;;) Line 1448  for (;;)
1448        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
1449        if (!md->endonly)        if (!md->endonly)
1450          {          {
1451          if (eptr < md->end_subject - 1 ||          if (eptr != md->end_subject &&
1452             (eptr == md->end_subject - 1 && *eptr != NEWLINE))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1453            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1454          ecode++;          ecode++;
1455          break;          break;
1456          }          }
1457        }        }
1458      /* ... else fall through */      /* ... else fall through for endonly */
1459    
1460      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1461    
# Line 1226  for (;;) Line 1467  for (;;)
1467      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1468    
1469      case OP_EODN:      case OP_EODN:
1470      if (eptr < md->end_subject - 1 ||      if (eptr != md->end_subject &&
1471         (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1472          RRETURN(MATCH_NOMATCH);
1473      ecode++;      ecode++;
1474      break;      break;
1475    
# Line 1239  for (;;) Line 1481  for (;;)
1481    
1482        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1483        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
1484        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1485          partial matching. */
1486    
1487  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1488        if (utf8)        if (utf8)
1489          {          {
1490          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1491            {            {
1492            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1493            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1494              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1495            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1496            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1497            }            }
1498          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1499              {
1500              SCHECK_PARTIAL();
1501              cur_is_word = FALSE;
1502              }
1503            else
1504            {            {
1505            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1506            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1260  for (;;) Line 1509  for (;;)
1509        else        else
1510  #endif  #endif
1511    
1512        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1513    
1514          {          {
1515          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1516            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1517          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1518            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1519              }
1520            if (eptr >= md->end_subject)
1521              {
1522              SCHECK_PARTIAL();
1523              cur_is_word = FALSE;
1524              }
1525            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1526          }          }
1527    
1528        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1280  for (;;) Line 1536  for (;;)
1536      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1537    
1538      case OP_ANY:      case OP_ANY:
1539      if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1540        /* Fall through */
1541    
1542        case OP_ALLANY:
1543        if (eptr++ >= md->end_subject)
1544          {
1545          SCHECK_PARTIAL();
1546        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1547      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);        }
1548  #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  
1549      ecode++;      ecode++;
1550      break;      break;
1551    
# Line 1294  for (;;) Line 1553  for (;;)
1553      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1554    
1555      case OP_ANYBYTE:      case OP_ANYBYTE:
1556      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1557          {
1558          SCHECK_PARTIAL();
1559          RRETURN(MATCH_NOMATCH);
1560          }
1561      ecode++;      ecode++;
1562      break;      break;
1563    
1564      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1565      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1566          {
1567          SCHECK_PARTIAL();
1568          RRETURN(MATCH_NOMATCH);
1569          }
1570      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1571      if (      if (
1572  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1312  for (;;) Line 1579  for (;;)
1579      break;      break;
1580    
1581      case OP_DIGIT:      case OP_DIGIT:
1582      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1583          {
1584          SCHECK_PARTIAL();
1585          RRETURN(MATCH_NOMATCH);
1586          }
1587      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1588      if (      if (
1589  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1325  for (;;) Line 1596  for (;;)
1596      break;      break;
1597    
1598      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1599      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1600          {
1601          SCHECK_PARTIAL();
1602          RRETURN(MATCH_NOMATCH);
1603          }
1604      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1605      if (      if (
1606  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1338  for (;;) Line 1613  for (;;)
1613      break;      break;
1614    
1615      case OP_WHITESPACE:      case OP_WHITESPACE:
1616      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1617          {
1618          SCHECK_PARTIAL();
1619          RRETURN(MATCH_NOMATCH);
1620          }
1621      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1622      if (      if (
1623  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1351  for (;;) Line 1630  for (;;)
1630      break;      break;
1631    
1632      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1633      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1634          {
1635          SCHECK_PARTIAL();
1636          RRETURN(MATCH_NOMATCH);
1637          }
1638      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1639      if (      if (
1640  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1364  for (;;) Line 1647  for (;;)
1647      break;      break;
1648    
1649      case OP_WORDCHAR:      case OP_WORDCHAR:
1650      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1651          {
1652          SCHECK_PARTIAL();
1653          RRETURN(MATCH_NOMATCH);
1654          }
1655      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1656      if (      if (
1657  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1376  for (;;) Line 1663  for (;;)
1663      ecode++;      ecode++;
1664      break;      break;
1665    
1666  #ifdef SUPPORT_UCP      case OP_ANYNL:
1667      /* Check the next character by Unicode property. We will get here only      if (eptr >= md->end_subject)
1668      if the support is in the binary; otherwise a compile-time error occurs. */        {
1669          SCHECK_PARTIAL();
1670      case OP_PROP:        RRETURN(MATCH_NOMATCH);
1671      case OP_NOTPROP:        }
     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);  
1672      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1673        switch(c)
1674        {        {
1675        int chartype, script;        default: RRETURN(MATCH_NOMATCH);
1676        int category = _pcre_ucp_findprop(c, &chartype, &script);        case 0x000d:
1677          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1678          break;
1679    
1680        switch(ecode[1])        case 0x000a:
1681          {        break;
         case PT_ANY:  
         if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);  
         break;  
1682    
1683          case PT_LAMP:        case 0x000b:
1684          if ((chartype == ucp_Lu ||        case 0x000c:
1685               chartype == ucp_Ll ||        case 0x0085:
1686               chartype == ucp_Lt) == (op == OP_NOTPROP))        case 0x2028:
1687            RRETURN(MATCH_NOMATCH);        case 0x2029:
1688          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1689          break;
1690          }
1691        ecode++;
1692        break;
1693    
1694        case OP_NOT_HSPACE:
1695        if (eptr >= md->end_subject)
1696          {
1697          SCHECK_PARTIAL();
1698          RRETURN(MATCH_NOMATCH);
1699          }
1700        GETCHARINCTEST(c, eptr);
1701        switch(c)
1702          {
1703          default: break;
1704          case 0x09:      /* HT */
1705          case 0x20:      /* SPACE */
1706          case 0xa0:      /* NBSP */
1707          case 0x1680:    /* OGHAM SPACE MARK */
1708          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1709          case 0x2000:    /* EN QUAD */
1710          case 0x2001:    /* EM QUAD */
1711          case 0x2002:    /* EN SPACE */
1712          case 0x2003:    /* EM SPACE */
1713          case 0x2004:    /* THREE-PER-EM SPACE */
1714          case 0x2005:    /* FOUR-PER-EM SPACE */
1715          case 0x2006:    /* SIX-PER-EM SPACE */
1716          case 0x2007:    /* FIGURE SPACE */
1717          case 0x2008:    /* PUNCTUATION SPACE */
1718          case 0x2009:    /* THIN SPACE */
1719          case 0x200A:    /* HAIR SPACE */
1720          case 0x202f:    /* NARROW NO-BREAK SPACE */
1721          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1722          case 0x3000:    /* IDEOGRAPHIC SPACE */
1723          RRETURN(MATCH_NOMATCH);
1724          }
1725        ecode++;
1726        break;
1727    
1728        case OP_HSPACE:
1729        if (eptr >= md->end_subject)
1730          {
1731          SCHECK_PARTIAL();
1732          RRETURN(MATCH_NOMATCH);
1733          }
1734        GETCHARINCTEST(c, eptr);
1735        switch(c)
1736          {
1737          default: RRETURN(MATCH_NOMATCH);
1738          case 0x09:      /* HT */
1739          case 0x20:      /* SPACE */
1740          case 0xa0:      /* NBSP */
1741          case 0x1680:    /* OGHAM SPACE MARK */
1742          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1743          case 0x2000:    /* EN QUAD */
1744          case 0x2001:    /* EM QUAD */
1745          case 0x2002:    /* EN SPACE */
1746          case 0x2003:    /* EM SPACE */
1747          case 0x2004:    /* THREE-PER-EM SPACE */
1748          case 0x2005:    /* FOUR-PER-EM SPACE */
1749          case 0x2006:    /* SIX-PER-EM SPACE */
1750          case 0x2007:    /* FIGURE SPACE */
1751          case 0x2008:    /* PUNCTUATION SPACE */
1752          case 0x2009:    /* THIN SPACE */
1753          case 0x200A:    /* HAIR SPACE */
1754          case 0x202f:    /* NARROW NO-BREAK SPACE */
1755          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1756          case 0x3000:    /* IDEOGRAPHIC SPACE */
1757          break;
1758          }
1759        ecode++;
1760        break;
1761    
1762        case OP_NOT_VSPACE:
1763        if (eptr >= md->end_subject)
1764          {
1765          SCHECK_PARTIAL();
1766          RRETURN(MATCH_NOMATCH);
1767          }
1768        GETCHARINCTEST(c, eptr);
1769        switch(c)
1770          {
1771          default: break;
1772          case 0x0a:      /* LF */
1773          case 0x0b:      /* VT */
1774          case 0x0c:      /* FF */
1775          case 0x0d:      /* CR */
1776          case 0x85:      /* NEL */
1777          case 0x2028:    /* LINE SEPARATOR */
1778          case 0x2029:    /* PARAGRAPH SEPARATOR */
1779          RRETURN(MATCH_NOMATCH);
1780          }
1781        ecode++;
1782        break;
1783    
1784        case OP_VSPACE:
1785        if (eptr >= md->end_subject)
1786          {
1787          SCHECK_PARTIAL();
1788          RRETURN(MATCH_NOMATCH);
1789          }
1790        GETCHARINCTEST(c, eptr);
1791        switch(c)
1792          {
1793          default: RRETURN(MATCH_NOMATCH);
1794          case 0x0a:      /* LF */
1795          case 0x0b:      /* VT */
1796          case 0x0c:      /* FF */
1797          case 0x0d:      /* CR */
1798          case 0x85:      /* NEL */
1799          case 0x2028:    /* LINE SEPARATOR */
1800          case 0x2029:    /* PARAGRAPH SEPARATOR */
1801          break;
1802          }
1803        ecode++;
1804        break;
1805    
1806    #ifdef SUPPORT_UCP
1807        /* Check the next character by Unicode property. We will get here only
1808        if the support is in the binary; otherwise a compile-time error occurs. */
1809    
1810        case OP_PROP:
1811        case OP_NOTPROP:
1812        if (eptr >= md->end_subject)
1813          {
1814          SCHECK_PARTIAL();
1815          RRETURN(MATCH_NOMATCH);
1816          }
1817        GETCHARINCTEST(c, eptr);
1818          {
1819          const ucd_record *prop = GET_UCD(c);
1820    
1821          switch(ecode[1])
1822            {
1823            case PT_ANY:
1824            if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
1825            break;
1826    
1827            case PT_LAMP:
1828            if ((prop->chartype == ucp_Lu ||
1829                 prop->chartype == ucp_Ll ||
1830                 prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1831              RRETURN(MATCH_NOMATCH);
1832           break;           break;
1833    
1834          case PT_GC:          case PT_GC:
1835          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1836            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1837          break;          break;
1838    
1839          case PT_PC:          case PT_PC:
1840          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1841            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1842          break;          break;
1843    
1844          case PT_SC:          case PT_SC:
1845          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1846            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1847          break;          break;
1848    
1849          default:          default:
1850          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
1851          }          }
1852    
1853        ecode += 3;        ecode += 3;
# Line 1429  for (;;) Line 1858  for (;;)
1858      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
1859    
1860      case OP_EXTUNI:      case OP_EXTUNI:
1861      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1862          {
1863          SCHECK_PARTIAL();
1864          RRETURN(MATCH_NOMATCH);
1865          }
1866      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1867        {        {
1868        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1869        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1870        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1871          {          {
# Line 1442  for (;;) Line 1874  for (;;)
1874            {            {
1875            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1876            }            }
1877          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1878          if (category != ucp_M) break;          if (category != ucp_M) break;
1879          eptr += len;          eptr += len;
1880          }          }
# Line 1463  for (;;) Line 1895  for (;;)
1895      case OP_REF:      case OP_REF:
1896        {        {
1897        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1898        ecode += 3;                                 /* Advance past item */        ecode += 3;
1899    
1900          /* If the reference is unset, there are two possibilities:
1901    
1902          (a) In the default, Perl-compatible state, set the length to be longer
1903          than the amount of subject left; this ensures that every attempt at a
1904          match fails. We can't just fail here, because of the possibility of
1905          quantifiers with zero minima.
1906    
1907        /* If the reference is unset, set the length to be longer than the amount        (b) If the JavaScript compatibility flag is set, set the length to zero
1908        of subject left; this ensures that every attempt at a match fails. We        so that the back reference matches an empty string.
1909        can't just fail here, because of the possibility of quantifiers with zero  
1910        minima. */        Otherwise, set the length to the length of what was matched by the
1911          referenced subpattern. */
1912        length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
1913          md->end_subject - eptr + 1 :        if (offset >= offset_top || md->offset_vector[offset] < 0)
1914          md->offset_vector[offset+1] - md->offset_vector[offset];          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1915          else
1916            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1917    
1918        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1919    
# Line 1501  for (;;) Line 1942  for (;;)
1942          break;          break;
1943    
1944          default:               /* No repeat follows */          default:               /* No repeat follows */
1945          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1946              {
1947              CHECK_PARTIAL();
1948              RRETURN(MATCH_NOMATCH);
1949              }
1950          eptr += length;          eptr += length;
1951          continue;              /* With the main loop */          continue;              /* With the main loop */
1952          }          }
# Line 1517  for (;;) Line 1962  for (;;)
1962    
1963        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
1964          {          {
1965          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1966              {
1967              CHECK_PARTIAL();
1968              RRETURN(MATCH_NOMATCH);
1969              }
1970          eptr += length;          eptr += length;
1971          }          }
1972    
# Line 1532  for (;;) Line 1981  for (;;)
1981          {          {
1982          for (fi = min;; fi++)          for (fi = min;; fi++)
1983            {            {
1984            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1985            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1986            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
1987              if (!match_ref(offset, eptr, length, md, ims))
1988                {
1989                CHECK_PARTIAL();
1990              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
1991                }
1992            eptr += length;            eptr += length;
1993            }            }
1994          /* Control never gets here */          /* Control never gets here */
# Line 1553  for (;;) Line 2006  for (;;)
2006            }            }
2007          while (eptr >= pp)          while (eptr >= pp)
2008            {            {
2009            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2010            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2011            eptr -= length;            eptr -= length;
2012            }            }
# Line 1562  for (;;) Line 2015  for (;;)
2015        }        }
2016      /* Control never gets here */      /* Control never gets here */
2017    
   
   
2018      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2019      used when all the characters in the class have values in the range 0-255,      used when all the characters in the class have values in the range 0-255,
2020      and either the matching is caseful, or the characters are in the range      and either the matching is caseful, or the characters are in the range
# Line 1618  for (;;) Line 2069  for (;;)
2069          {          {
2070          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2071            {            {
2072            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2073                {
2074                SCHECK_PARTIAL();
2075                RRETURN(MATCH_NOMATCH);
2076                }
2077            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2078            if (c > 255)            if (c > 255)
2079              {              {
# Line 1636  for (;;) Line 2091  for (;;)
2091          {          {
2092          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2093            {            {
2094            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2095                {
2096                SCHECK_PARTIAL();
2097                RRETURN(MATCH_NOMATCH);
2098                }
2099            c = *eptr++;            c = *eptr++;
2100            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2101            }            }
# Line 1658  for (;;) Line 2117  for (;;)
2117            {            {
2118            for (fi = min;; fi++)            for (fi = min;; fi++)
2119              {              {
2120              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2121              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2122              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2123                if (eptr >= md->end_subject)
2124                  {
2125                  SCHECK_PARTIAL();
2126                  RRETURN(MATCH_NOMATCH);
2127                  }
2128              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2129              if (c > 255)              if (c > 255)
2130                {                {
# Line 1678  for (;;) Line 2142  for (;;)
2142            {            {
2143            for (fi = min;; fi++)            for (fi = min;; fi++)
2144              {              {
2145              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2146              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2147              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2148                if (eptr >= md->end_subject)
2149                  {
2150                  SCHECK_PARTIAL();
2151                  RRETURN(MATCH_NOMATCH);
2152                  }
2153              c = *eptr++;              c = *eptr++;
2154              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2155              }              }
# Line 1715  for (;;) Line 2184  for (;;)
2184              }              }
2185            for (;;)            for (;;)
2186              {              {
2187              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2188              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2189              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2190              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1734  for (;;) Line 2203  for (;;)
2203              }              }
2204            while (eptr >= pp)            while (eptr >= pp)
2205              {              {
2206              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2207              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2208              eptr--;              eptr--;
2209              }              }
# Line 1747  for (;;) Line 2216  for (;;)
2216    
2217    
2218      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2219      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2220        mode, because Unicode properties are supported in non-UTF-8 mode. */
2221    
2222  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2223      case OP_XCLASS:      case OP_XCLASS:
# Line 1788  for (;;) Line 2258  for (;;)
2258    
2259        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2260          {          {
2261          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2262          GETCHARINC(c, eptr);            {
2263              SCHECK_PARTIAL();
2264              RRETURN(MATCH_NOMATCH);
2265              }
2266            GETCHARINCTEST(c, eptr);
2267          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2268          }          }
2269    
# Line 1805  for (;;) Line 2279  for (;;)
2279          {          {
2280          for (fi = min;; fi++)          for (fi = min;; fi++)
2281            {            {
2282            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2283            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2284            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2285            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2286                {
2287                SCHECK_PARTIAL();
2288                RRETURN(MATCH_NOMATCH);
2289                }
2290              GETCHARINCTEST(c, eptr);
2291            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2292            }            }
2293          /* Control never gets here */          /* Control never gets here */
# Line 1823  for (;;) Line 2302  for (;;)
2302            {            {
2303            int len = 1;            int len = 1;
2304            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2305            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2306            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2307            eptr += len;            eptr += len;
2308            }            }
2309          for(;;)          for(;;)
2310            {            {
2311            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2312            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2313            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2314            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2315            }            }
2316          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2317          }          }
# Line 1850  for (;;) Line 2329  for (;;)
2329        length = 1;        length = 1;
2330        ecode++;        ecode++;
2331        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2332        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2333            {
2334            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2335            RRETURN(MATCH_NOMATCH);
2336            }
2337        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2338        }        }
2339      else      else
# Line 1858  for (;;) Line 2341  for (;;)
2341    
2342      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2343        {        {
2344        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2345            {
2346            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2347            RRETURN(MATCH_NOMATCH);
2348            }
2349        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2350        ecode += 2;        ecode += 2;
2351        }        }
# Line 1874  for (;;) Line 2361  for (;;)
2361        ecode++;        ecode++;
2362        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2363    
2364        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2365            {
2366            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2367            RRETURN(MATCH_NOMATCH);
2368            }
2369    
2370        /* If the pattern character's value is < 128, we have only one byte, and        /* If the pattern character's value is < 128, we have only one byte, and
2371        can use the fast lookup table. */        can use the fast lookup table. */
# Line 1888  for (;;) Line 2379  for (;;)
2379    
2380        else        else
2381          {          {
2382          int dc;          unsigned int dc;
2383          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2384          ecode += length;          ecode += length;
2385    
# Line 1898  for (;;) Line 2389  for (;;)
2389          if (fc != dc)          if (fc != dc)
2390            {            {
2391  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2392            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2393  #endif  #endif
2394              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2395            }            }
# Line 1909  for (;;) Line 2400  for (;;)
2400    
2401      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2402        {        {
2403        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2404            {
2405            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2406            RRETURN(MATCH_NOMATCH);
2407            }
2408        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2409        ecode += 2;        ecode += 2;
2410        }        }
2411      break;      break;
2412    
2413      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2414    
2415      case OP_EXACT:      case OP_EXACT:
2416      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2417      ecode += 3;      ecode += 3;
2418      goto REPEATCHAR;      goto REPEATCHAR;
2419    
2420        case OP_POSUPTO:
2421        possessive = TRUE;
2422        /* Fall through */
2423    
2424      case OP_UPTO:      case OP_UPTO:
2425      case OP_MINUPTO:      case OP_MINUPTO:
2426      min = 0;      min = 0;
# Line 1930  for (;;) Line 2429  for (;;)
2429      ecode += 3;      ecode += 3;
2430      goto REPEATCHAR;      goto REPEATCHAR;
2431    
2432        case OP_POSSTAR:
2433        possessive = TRUE;
2434        min = 0;
2435        max = INT_MAX;
2436        ecode++;
2437        goto REPEATCHAR;
2438    
2439        case OP_POSPLUS:
2440        possessive = TRUE;
2441        min = 1;
2442        max = INT_MAX;
2443        ecode++;
2444        goto REPEATCHAR;
2445    
2446        case OP_POSQUERY:
2447        possessive = TRUE;
2448        min = 0;
2449        max = 1;
2450        ecode++;
2451        goto REPEATCHAR;
2452    
2453      case OP_STAR:      case OP_STAR:
2454      case OP_MINSTAR:      case OP_MINSTAR:
2455      case OP_PLUS:      case OP_PLUS:
# Line 1938  for (;;) Line 2458  for (;;)
2458      case OP_MINQUERY:      case OP_MINQUERY:
2459      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2460      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2461    
2462      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2463      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2464      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2465    
2466      /* Common code for all repeated single-character matches. We can give      /* Common code for all repeated single-character matches. */
     up quickly if there are fewer than the minimum number of characters left in  
     the subject. */  
2467    
2468      REPEATCHAR:      REPEATCHAR:
2469  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1953  for (;;) Line 2472  for (;;)
2472        length = 1;        length = 1;
2473        charptr = ecode;        charptr = ecode;
2474        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2475        ecode += length;        ecode += length;
2476    
2477        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 1961  for (;;) Line 2479  for (;;)
2479    
2480        if (length > 1)        if (length > 1)
2481          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2482  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2483          int othercase;          unsigned int othercase;
2484          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2485              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2486            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2487            else oclength = 0;
2488  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2489    
2490          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2491            {            {
2492            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2493            /* Need braces because of following else */              memcmp(eptr, charptr, length) == 0) eptr += length;
2494            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2495              else if (oclength > 0 &&
2496                       eptr <= md->end_subject - oclength &&
2497                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2498    #endif  /* SUPPORT_UCP */
2499            else            else
2500              {              {
2501              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2502              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2503              }              }
2504            }            }
2505    
# Line 1990  for (;;) Line 2509  for (;;)
2509            {            {
2510            for (fi = min;; fi++)            for (fi = min;; fi++)
2511              {              {
2512              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2513              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2514              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2515              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2516              /* Need braces because of following else */                memcmp(eptr, charptr, length) == 0) eptr += length;
2517              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2518                else if (oclength > 0 &&
2519                         eptr <= md->end_subject - oclength &&
2520                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2521    #endif  /* SUPPORT_UCP */
2522              else              else
2523                {                {
2524                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2525                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2526                }                }
2527              }              }
2528            /* Control never gets here */            /* Control never gets here */
2529            }            }
2530          else  
2531            else  /* Maximize */
2532            {            {
2533            pp = eptr;            pp = eptr;
2534            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2535              {              {
2536              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2537              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2538              else if (oclength == 0) break;  #ifdef SUPPORT_UCP
2539              else              else if (oclength > 0 &&
2540                {                       eptr <= md->end_subject - oclength &&
2541                if (memcmp(eptr, occhars, oclength) != 0) break;                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2542                eptr += oclength;  #endif  /* SUPPORT_UCP */
2543                }              else break;
2544                }
2545    
2546              if (possessive) continue;
2547    
2548              for(;;)
2549                {
2550                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2551                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2552                if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2553    #ifdef SUPPORT_UCP
2554                eptr--;
2555                BACKCHAR(eptr);
2556    #else   /* without SUPPORT_UCP */
2557                eptr -= length;
2558    #endif  /* SUPPORT_UCP */
2559              }              }
           while (eptr >= pp)  
            {  
            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
            eptr -= length;  
            }  
           RRETURN(MATCH_NOMATCH);  
2560            }            }
2561          /* Control never gets here */          /* Control never gets here */
2562          }          }
# Line 2037  for (;;) Line 2569  for (;;)
2569  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2570    
2571      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2572        {  
2573        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2574    
2575      /* The value of fc at this point is always less than 256, though we may or      /* The value of fc at this point is always less than 256, though we may or
2576      may not be in UTF-8 mode. The code is duplicated for the caseless and      may not be in UTF-8 mode. The code is duplicated for the caseless and
# Line 2058  for (;;) Line 2588  for (;;)
2588        {        {
2589        fc = md->lcc[fc];        fc = md->lcc[fc];
2590        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2591            {
2592            if (eptr >= md->end_subject)
2593              {
2594              SCHECK_PARTIAL();
2595              RRETURN(MATCH_NOMATCH);
2596              }
2597          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2598            }
2599        if (min == max) continue;        if (min == max) continue;
2600        if (minimize)        if (minimize)
2601          {          {
2602          for (fi = min;; fi++)          for (fi = min;; fi++)
2603            {            {
2604            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2605            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2606            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2607                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2608                {
2609                SCHECK_PARTIAL();
2610              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2611                }
2612              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2613            }            }
2614          /* Control never gets here */          /* Control never gets here */
2615          }          }
2616        else        else  /* Maximize */
2617          {          {
2618          pp = eptr;          pp = eptr;
2619          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2080  for (;;) Line 2621  for (;;)
2621            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2622            eptr++;            eptr++;
2623            }            }
2624    
2625            if (possessive) continue;
2626    
2627          while (eptr >= pp)          while (eptr >= pp)
2628            {            {
2629            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2630            eptr--;            eptr--;
2631            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2632            }            }
# Line 2095  for (;;) Line 2639  for (;;)
2639    
2640      else      else
2641        {        {
2642        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2643            {
2644            if (eptr >= md->end_subject)
2645              {
2646              SCHECK_PARTIAL();
2647              RRETURN(MATCH_NOMATCH);
2648              }
2649            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2650            }
2651    
2652        if (min == max) continue;        if (min == max) continue;
2653    
2654        if (minimize)        if (minimize)
2655          {          {
2656          for (fi = min;; fi++)          for (fi = min;; fi++)
2657            {            {
2658            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2659            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2660            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2661              if (eptr >= md->end_subject)
2662                {
2663                SCHECK_PARTIAL();
2664              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2665                }
2666              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2667            }            }
2668          /* Control never gets here */          /* Control never gets here */
2669          }          }
2670        else        else  /* Maximize */
2671          {          {
2672          pp = eptr;          pp = eptr;
2673          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2116  for (;;) Line 2675  for (;;)
2675            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2676            eptr++;            eptr++;
2677            }            }
2678            if (possessive) continue;
2679    
2680          while (eptr >= pp)          while (eptr >= pp)
2681            {            {
2682            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2683            eptr--;            eptr--;
2684            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2685            }            }
# Line 2131  for (;;) Line 2692  for (;;)
2692      checking can be multibyte. */      checking can be multibyte. */
2693    
2694      case OP_NOT:      case OP_NOT:
2695      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2696          {
2697          SCHECK_PARTIAL();
2698          RRETURN(MATCH_NOMATCH);
2699          }
2700      ecode++;      ecode++;
2701      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2702      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2168  for (;;) Line 2733  for (;;)
2733      ecode += 3;      ecode += 3;
2734      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2735    
2736        case OP_NOTPOSSTAR:
2737        possessive = TRUE;
2738        min = 0;
2739        max = INT_MAX;
2740        ecode++;
2741        goto REPEATNOTCHAR;
2742    
2743        case OP_NOTPOSPLUS:
2744        possessive = TRUE;
2745        min = 1;
2746        max = INT_MAX;
2747        ecode++;
2748        goto REPEATNOTCHAR;
2749    
2750        case OP_NOTPOSQUERY:
2751        possessive = TRUE;
2752        min = 0;
2753        max = 1;
2754        ecode++;
2755        goto REPEATNOTCHAR;
2756    
2757        case OP_NOTPOSUPTO:
2758        possessive = TRUE;
2759        min = 0;
2760        max = GET2(ecode, 1);
2761        ecode += 3;
2762        goto REPEATNOTCHAR;
2763    
2764      case OP_NOTSTAR:      case OP_NOTSTAR:
2765      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2766      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2180  for (;;) Line 2773  for (;;)
2773      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2774      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2775    
2776      /* Common code for all repeated single-byte matches. We can give up quickly      /* Common code for all repeated single-byte matches. */
     if there are fewer than the minimum number of bytes left in the  
     subject. */  
2777    
2778      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2779      fc = *ecode++;      fc = *ecode++;
2780    
2781      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
# Line 2207  for (;;) Line 2797  for (;;)
2797        /* UTF-8 mode */        /* UTF-8 mode */
2798        if (utf8)        if (utf8)
2799          {          {
2800          register int d;          register unsigned int d;
2801          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2802            {            {
2803              if (eptr >= md->end_subject)
2804                {
2805                SCHECK_PARTIAL();
2806                RRETURN(MATCH_NOMATCH);
2807                }
2808            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2809            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2810            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2221  for (;;) Line 2816  for (;;)
2816        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2817          {          {
2818          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2819              {
2820              if (eptr >= md->end_subject)
2821                {
2822                SCHECK_PARTIAL();
2823                RRETURN(MATCH_NOMATCH);
2824                }
2825            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2826              }
2827          }          }
2828    
2829        if (min == max) continue;        if (min == max) continue;
# Line 2232  for (;;) Line 2834  for (;;)
2834          /* UTF-8 mode */          /* UTF-8 mode */
2835          if (utf8)          if (utf8)
2836            {            {
2837            register int d;            register unsigned int d;
2838            for (fi = min;; fi++)            for (fi = min;; fi++)
2839              {              {
2840              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2841              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2842                if (fi >= max) RRETURN(MATCH_NOMATCH);
2843                if (eptr >= md->end_subject)
2844                  {
2845                  SCHECK_PARTIAL();
2846                  RRETURN(MATCH_NOMATCH);
2847                  }
2848              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2849              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2850              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2851              }              }
2852            }            }
2853          else          else
# Line 2249  for (;;) Line 2856  for (;;)
2856            {            {
2857            for (fi = min;; fi++)            for (fi = min;; fi++)
2858              {              {
2859              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2860              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2861              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
2862                if (eptr >= md->end_subject)
2863                  {
2864                  SCHECK_PARTIAL();
2865                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2866                  }
2867                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2868              }              }
2869            }            }
2870          /* Control never gets here */          /* Control never gets here */
# Line 2268  for (;;) Line 2880  for (;;)
2880          /* UTF-8 mode */          /* UTF-8 mode */
2881          if (utf8)          if (utf8)
2882            {            {
2883            register int d;            register unsigned int d;
2884            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2885              {              {
2886              int len = 1;              int len = 1;
# Line 2278  for (;;) Line 2890  for (;;)
2890              if (fc == d) break;              if (fc == d) break;
2891              eptr += len;              eptr += len;
2892              }              }
2893            for(;;)          if (possessive) continue;
2894            for(;;)
2895              {              {
2896              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2897              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2898              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2899              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2295  for (;;) Line 2908  for (;;)
2908              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2909              eptr++;              eptr++;
2910              }              }
2911              if (possessive) continue;
2912            while (eptr >= pp)            while (eptr >= pp)
2913              {              {
2914              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2915              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2916              eptr--;              eptr--;
2917              }              }
# Line 2316  for (;;) Line 2930  for (;;)
2930        /* UTF-8 mode */        /* UTF-8 mode */
2931        if (utf8)        if (utf8)
2932          {          {
2933          register int d;          register unsigned int d;
2934          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2935            {            {
2936              if (eptr >= md->end_subject)
2937                {
2938                SCHECK_PARTIAL();
2939                RRETURN(MATCH_NOMATCH);
2940                }
2941            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2942            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
2943            }            }
# Line 2328  for (;;) Line 2947  for (;;)
2947        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2948          {          {
2949          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2950              {
2951              if (eptr >= md->end_subject)
2952                {
2953                SCHECK_PARTIAL();
2954                RRETURN(MATCH_NOMATCH);
2955                }
2956            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2957              }
2958          }          }
2959    
2960        if (min == max) continue;        if (min == max) continue;
# Line 2339  for (;;) Line 2965  for (;;)
2965          /* UTF-8 mode */          /* UTF-8 mode */
2966          if (utf8)          if (utf8)
2967            {            {
2968            register int d;            register unsigned int d;
2969            for (fi = min;; fi++)            for (fi = min;; fi++)
2970              {              {
2971              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2972              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2973              GETCHARINC(d, eptr);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2974              if (fi >= max || eptr >= md->end_subject || fc == d)              if (eptr >= md->end_subject)
2975                  {
2976                  SCHECK_PARTIAL();
2977                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2978                  }
2979                GETCHARINC(d, eptr);
2980                if (fc == d) RRETURN(MATCH_NOMATCH);
2981              }              }
2982            }            }
2983          else          else
# Line 2355  for (;;) Line 2986  for (;;)
2986            {            {
2987            for (fi = min;; fi++)            for (fi = min;; fi++)
2988              {              {
2989              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2990              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2991              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
2992                if (eptr >= md->end_subject)
2993                  {
2994                  SCHECK_PARTIAL();
2995                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2996                  }
2997                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2998              }              }
2999            }            }
3000          /* Control never gets here */          /* Control never gets here */
# Line 2374  for (;;) Line 3010  for (;;)
3010          /* UTF-8 mode */          /* UTF-8 mode */
3011          if (utf8)          if (utf8)
3012            {            {
3013            register int d;            register unsigned int d;
3014            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3015              {              {
3016              int len = 1;              int len = 1;
# Line 2383  for (;;) Line 3019  for (;;)
3019              if (fc == d) break;              if (fc == d) break;
3020              eptr += len;              eptr += len;
3021              }              }
3022              if (possessive) continue;
3023            for(;;)            for(;;)
3024              {              {
3025              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3026              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3027              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3028              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2400  for (;;) Line 3037  for (;;)
3037              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
3038              eptr++;              eptr++;
3039              }              }
3040              if (possessive) continue;
3041            while (eptr >= pp)            while (eptr >= pp)
3042              {              {
3043              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3044              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3045              eptr--;              eptr--;
3046              }              }
# Line 2431  for (;;) Line 3069  for (;;)
3069      ecode += 3;      ecode += 3;
3070      goto REPEATTYPE;      goto REPEATTYPE;
3071    
3072        case OP_TYPEPOSSTAR:
3073        possessive = TRUE;
3074        min = 0;
3075        max = INT_MAX;
3076        ecode++;
3077        goto REPEATTYPE;
3078    
3079        case OP_TYPEPOSPLUS:
3080        possessive = TRUE;
3081        min = 1;
3082        max = INT_MAX;
3083        ecode++;
3084        goto REPEATTYPE;
3085    
3086        case OP_TYPEPOSQUERY:
3087        possessive = TRUE;
3088        min = 0;
3089        max = 1;
3090        ecode++;
3091        goto REPEATTYPE;
3092    
3093        case OP_TYPEPOSUPTO:
3094        possessive = TRUE;
3095        min = 0;
3096        max = GET2(ecode, 1);
3097        ecode += 3;
3098        goto REPEATTYPE;
3099    
3100      case OP_TYPESTAR:      case OP_TYPESTAR:
3101      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
3102      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2462  for (;;) Line 3128  for (;;)
3128    
3129      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3130      code for maximizing the speed, and do the type test once at the start      code for maximizing the speed, and do the type test once at the start
3131      (i.e. keep it out of the loop). Also we can test that there are at least      (i.e. keep it out of the loop). Separate the UTF-8 code completely as that
     the minimum number of bytes before we start. This isn't as effective in  
     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that  
3132      is tidier. Also separate the UCP code, which can be the same for both UTF-8      is tidier. Also separate the UCP code, which can be the same for both UTF-8
3133      and single-bytes. */      and single-bytes. */
3134    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3135      if (min > 0)      if (min > 0)
3136        {        {
3137  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2480  for (;;) Line 3143  for (;;)
3143            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3144            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3145              {              {
3146              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3147              GETCHARINC(c, eptr);                {
3148                  SCHECK_PARTIAL();
3149                  RRETURN(MATCH_NOMATCH);
3150                  }
3151                GETCHARINCTEST(c, eptr);
3152              }              }
3153            break;            break;
3154    
3155            case PT_LAMP:            case PT_LAMP:
3156            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3157              {              {
3158              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3159              GETCHARINC(c, eptr);                {
3160              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3161                  RRETURN(MATCH_NOMATCH);
3162                  }
3163                GETCHARINCTEST(c, eptr);
3164                prop_chartype = UCD_CHARTYPE(c);
3165              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3166                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3167                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2501  for (;;) Line 3172  for (;;)
3172            case PT_GC:            case PT_GC:
3173            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3174              {              {
3175              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3176              GETCHARINC(c, eptr);                {
3177              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3178                  RRETURN(MATCH_NOMATCH);
3179                  }
3180                GETCHARINCTEST(c, eptr);
3181                prop_category = UCD_CATEGORY(c);
3182              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3183                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3184              }              }
# Line 2512  for (;;) Line 3187  for (;;)
3187            case PT_PC:            case PT_PC:
3188            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3189              {              {
3190              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3191              GETCHARINC(c, eptr);                {
3192              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3193                  RRETURN(MATCH_NOMATCH);
3194                  }
3195                GETCHARINCTEST(c, eptr);
3196                prop_chartype = UCD_CHARTYPE(c);
3197              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3198                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3199              }              }
# Line 2523  for (;;) Line 3202  for (;;)
3202            case PT_SC:            case PT_SC:
3203            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3204              {              {
3205              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3206              GETCHARINC(c, eptr);                {
3207              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3208                  RRETURN(MATCH_NOMATCH);
3209                  }
3210                GETCHARINCTEST(c, eptr);
3211                prop_script = UCD_SCRIPT(c);
3212              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3213                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3214              }              }
# Line 2533  for (;;) Line 3216  for (;;)
3216    
3217            default:            default:
3218            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3219            }            }
3220          }          }
3221    
# Line 2544  for (;;) Line 3226  for (;;)
3226          {          {
3227          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3228            {            {
3229              if (eptr >= md->end_subject)
3230                {
3231                SCHECK_PARTIAL();
3232                RRETURN(MATCH_NOMATCH);
3233                }
3234            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3235            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3236            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3237            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3238              {              {
3239              int len = 1;              int len = 1;
3240              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3241                {                else { GETCHARLEN(c, eptr, len); }
3242                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3243              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3244              eptr += len;              eptr += len;
3245              }              }
# Line 2572  for (;;) Line 3257  for (;;)
3257          case OP_ANY:          case OP_ANY:
3258          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3259            {            {
3260            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3261               (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0))              {
3262                SCHECK_PARTIAL();
3263              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3264                }
3265              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3266              eptr++;
3267              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3268              }
3269            break;
3270    
3271            case OP_ALLANY:
3272            for (i = 1; i <= min; i++)
3273              {
3274              if (eptr >= md->end_subject)
3275                {
3276                SCHECK_PARTIAL();
3277                RRETURN(MATCH_NOMATCH);
3278                }
3279              eptr++;
3280            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3281            }            }
3282          break;          break;
3283    
3284          case OP_ANYBYTE:          case OP_ANYBYTE:
3285            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3286          eptr += min;          eptr += min;
3287          break;          break;
3288    
3289            case OP_ANYNL:
3290            for (i = 1; i <= min; i++)
3291              {
3292              if (eptr >= md->end_subject)
3293                {
3294                SCHECK_PARTIAL();
3295                RRETURN(MATCH_NOMATCH);
3296                }
3297              GETCHARINC(c, eptr);
3298              switch(c)
3299                {
3300                default: RRETURN(MATCH_NOMATCH);
3301                case 0x000d:
3302                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3303                break;
3304    
3305                case 0x000a:
3306                break;
3307    
3308                case 0x000b:
3309                case 0x000c:
3310                case 0x0085:
3311                case 0x2028:
3312                case 0x2029:
3313                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3314                break;
3315                }
3316              }
3317            break;
3318    
3319            case OP_NOT_HSPACE:
3320            for (i = 1; i <= min; i++)
3321              {
3322              if (eptr >= md->end_subject)
3323                {
3324                SCHECK_PARTIAL();
3325                RRETURN(MATCH_NOMATCH);
3326                }
3327              GETCHARINC(c, eptr);
3328              switch(c)
3329                {
3330                default: break;
3331                case 0x09:      /* HT */
3332                case 0x20:      /* SPACE */
3333                case 0xa0:      /* NBSP */
3334                case 0x1680:    /* OGHAM SPACE MARK */
3335                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3336                case 0x2000:    /* EN QUAD */
3337                case 0x2001:    /* EM QUAD */
3338                case 0x2002:    /* EN SPACE */
3339                case 0x2003:    /* EM SPACE */
3340                case 0x2004:    /* THREE-PER-EM SPACE */
3341                case 0x2005:    /* FOUR-PER-EM SPACE */
3342                case 0x2006:    /* SIX-PER-EM SPACE */
3343                case 0x2007:    /* FIGURE SPACE */
3344                case 0x2008:    /* PUNCTUATION SPACE */
3345                case 0x2009:    /* THIN SPACE */
3346                case 0x200A:    /* HAIR SPACE */
3347                case 0x202f:    /* NARROW NO-BREAK SPACE */
3348                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3349                case 0x3000:    /* IDEOGRAPHIC SPACE */
3350                RRETURN(MATCH_NOMATCH);
3351                }
3352              }
3353            break;
3354    
3355            case OP_HSPACE:
3356            for (i = 1; i <= min; i++)
3357              {
3358              if (eptr >= md->end_subject)
3359                {
3360                SCHECK_PARTIAL();
3361                RRETURN(MATCH_NOMATCH);
3362                }
3363              GETCHARINC(c, eptr);
3364              switch(c)
3365                {
3366                default: RRETURN(MATCH_NOMATCH);
3367                case 0x09:      /* HT */
3368                case 0x20:      /* SPACE */
3369                case 0xa0:      /* NBSP */
3370                case 0x1680:    /* OGHAM SPACE MARK */
3371                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3372                case 0x2000:    /* EN QUAD */
3373                case 0x2001:    /* EM QUAD */
3374                case 0x2002:    /* EN SPACE */
3375                case 0x2003:    /* EM SPACE */
3376                case 0x2004:    /* THREE-PER-EM SPACE */
3377                case 0x2005:    /* FOUR-PER-EM SPACE */
3378                case 0x2006:    /* SIX-PER-EM SPACE */
3379                case 0x2007:    /* FIGURE SPACE */
3380                case 0x2008:    /* PUNCTUATION SPACE */
3381                case 0x2009:    /* THIN SPACE */
3382                case 0x200A:    /* HAIR SPACE */
3383                case 0x202f:    /* NARROW NO-BREAK SPACE */
3384                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3385                case 0x3000:    /* IDEOGRAPHIC SPACE */
3386                break;
3387                }
3388              }
3389            break;
3390    
3391            case OP_NOT_VSPACE:
3392            for (i = 1; i <= min; i++)
3393              {
3394              if (eptr >= md->end_subject)
3395                {
3396                SCHECK_PARTIAL();
3397                RRETURN(MATCH_NOMATCH);
3398                }
3399              GETCHARINC(c, eptr);
3400              switch(c)
3401                {
3402                default: break;
3403                case 0x0a:      /* LF */
3404                case 0x0b:      /* VT */
3405                case 0x0c:      /* FF */
3406                case 0x0d:      /* CR */
3407                case 0x85:      /* NEL */
3408                case 0x2028:    /* LINE SEPARATOR */
3409                case 0x2029:    /* PARAGRAPH SEPARATOR */
3410                RRETURN(MATCH_NOMATCH);
3411                }
3412              }
3413            break;
3414    
3415            case OP_VSPACE:
3416            for (i = 1; i <= min; i++)
3417              {
3418              if (eptr >= md->end_subject)
3419                {
3420                SCHECK_PARTIAL();
3421                RRETURN(MATCH_NOMATCH);
3422                }
3423              GETCHARINC(c, eptr);
3424              switch(c)
3425                {
3426                default: RRETURN(MATCH_NOMATCH);
3427                case 0x0a:      /* LF */
3428                case 0x0b:      /* VT */
3429                case 0x0c:      /* FF */
3430                case 0x0d:      /* CR */
3431                case 0x85:      /* NEL */
3432                case 0x2028:    /* LINE SEPARATOR */
3433                case 0x2029:    /* PARAGRAPH SEPARATOR */
3434                break;
3435                }
3436              }
3437            break;
3438    
3439          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3440          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3441            {            {
3442            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3443                {
3444                SCHECK_PARTIAL();
3445                RRETURN(MATCH_NOMATCH);
3446                }
3447            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3448            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3449              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 2596  for (;;) Line 3453  for (;;)
3453          case OP_DIGIT:          case OP_DIGIT:
3454          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3455            {            {
3456            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3457               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3458                SCHECK_PARTIAL();
3459                RRETURN(MATCH_NOMATCH);
3460                }
3461              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3462              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3463            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3464            }            }
# Line 2606  for (;;) Line 3467  for (;;)
3467          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3468          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3469            {            {
3470            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3471               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3472                SCHECK_PARTIAL();
3473              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3474            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3475              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3476                RRETURN(MATCH_NOMATCH);
3477              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3478            }            }
3479          break;          break;
3480    
3481          case OP_WHITESPACE:          case OP_WHITESPACE:
3482          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3483            {            {
3484            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3485               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3486                SCHECK_PARTIAL();
3487                RRETURN(MATCH_NOMATCH);
3488                }
3489              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3490              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3491            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3492            }            }
# Line 2627  for (;;) Line 3496  for (;;)
3496          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3497            {            {
3498            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3499               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3500              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3501            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3502            }            }
3503          break;          break;
3504    
3505          case OP_WORDCHAR:          case OP_WORDCHAR:
3506          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3507            {            {
3508            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3509               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3510                SCHECK_PARTIAL();
3511                RRETURN(MATCH_NOMATCH);
3512                }
3513              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3514              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3515            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3516            }            }
# Line 2656  for (;;) Line 3529  for (;;)
3529        switch(ctype)        switch(ctype)
3530          {          {
3531          case OP_ANY:          case OP_ANY:
3532          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3533            {            {
3534            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3535              if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH);              {
3536                SCHECK_PARTIAL();
3537                RRETURN(MATCH_NOMATCH);
3538                }
3539              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3540              eptr++;
3541            }            }
3542          else eptr += min;          break;
3543    
3544            case OP_ALLANY:
3545            if (eptr > md->end_subject - min)
3546              {
3547              SCHECK_PARTIAL();
3548              RRETURN(MATCH_NOMATCH);
3549              }
3550            eptr += min;
3551          break;          break;
3552    
3553          case OP_ANYBYTE:          case OP_ANYBYTE:
3554            if (eptr > md->end_subject - min)
3555              {
3556              SCHECK_PARTIAL();
3557              RRETURN(MATCH_NOMATCH);
3558              }
3559          eptr += min;          eptr += min;
3560          break;          break;
3561    
3562            case OP_ANYNL:
3563            for (i = 1; i <= min; i++)
3564              {
3565              if (eptr >= md->end_subject)
3566                {
3567                SCHECK_PARTIAL();
3568                RRETURN(MATCH_NOMATCH);
3569                }
3570              switch(*eptr++)
3571                {
3572                default: RRETURN(MATCH_NOMATCH);
3573                case 0x000d:
3574                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3575                break;
3576                case 0x000a:
3577                break;
3578    
3579                case 0x000b:
3580                case 0x000c:
3581                case 0x0085:
3582                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3583                break;
3584                }
3585              }
3586            break;
3587    
3588            case OP_NOT_HSPACE:
3589            for (i = 1; i <= min; i++)
3590              {
3591              if (eptr >= md->end_subject)
3592                {
3593                SCHECK_PARTIAL();
3594                RRETURN(MATCH_NOMATCH);
3595                }
3596              switch(*eptr++)
3597                {
3598                default: break;
3599                case 0x09:      /* HT */
3600                case 0x20:      /* SPACE */
3601                case 0xa0:      /* NBSP */
3602                RRETURN(MATCH_NOMATCH);
3603                }
3604              }
3605            break;
3606    
3607            case OP_HSPACE:
3608            for (i = 1; i <= min; i++)
3609              {
3610              if (eptr >= md->end_subject)
3611                {
3612                SCHECK_PARTIAL();
3613                RRETURN(MATCH_NOMATCH);
3614                }
3615              switch(*eptr++)
3616                {
3617                default: RRETURN(MATCH_NOMATCH);
3618                case 0x09:      /* HT */
3619                case 0x20:      /* SPACE */
3620                case 0xa0:      /* NBSP */
3621                break;
3622                }
3623              }
3624            break;
3625    
3626            case OP_NOT_VSPACE:
3627            for (i = 1; i <= min; i++)
3628              {
3629              if (eptr >= md->end_subject)
3630                {
3631                SCHECK_PARTIAL();
3632                RRETURN(MATCH_NOMATCH);
3633                }
3634              switch(*eptr++)
3635                {
3636                default: break;
3637                case 0x0a:      /* LF */
3638                case 0x0b:      /* VT */
3639                case 0x0c:      /* FF */
3640                case 0x0d:      /* CR */
3641                case 0x85:      /* NEL */
3642                RRETURN(MATCH_NOMATCH);
3643                }
3644              }
3645            break;
3646    
3647            case OP_VSPACE:
3648            for (i = 1; i <= min; i++)
3649              {
3650              if (eptr >= md->end_subject)
3651                {
3652                SCHECK_PARTIAL();
3653                RRETURN(MATCH_NOMATCH);
3654                }
3655              switch(*eptr++)
3656                {
3657                default: RRETURN(MATCH_NOMATCH);
3658                case 0x0a:      /* LF */
3659                case 0x0b:      /* VT */
3660                case 0x0c:      /* FF */
3661                case 0x0d:      /* CR */
3662                case 0x85:      /* NEL */
3663                break;
3664                }
3665              }
3666            break;
3667    
3668          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3669          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3670              {
3671              if (eptr >= md->end_subject)
3672                {
3673                SCHECK_PARTIAL();
3674                RRETURN(MATCH_NOMATCH);
3675                }
3676            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3677              }
3678          break;          break;
3679    
3680          case OP_DIGIT:          case OP_DIGIT:
3681          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3682              {
3683              if (eptr >= md->end_subject)
3684                {
3685                SCHECK_PARTIAL();
3686                RRETURN(MATCH_NOMATCH);
3687                }
3688            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3689              }
3690          break;          break;
3691    
3692          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3693          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3694              {
3695              if (eptr >= md->end_subject)
3696                {
3697                SCHECK_PARTIAL();
3698                RRETURN(MATCH_NOMATCH);
3699                }
3700            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3701              }
3702          break;          break;
3703    
3704          case OP_WHITESPACE:          case OP_WHITESPACE:
3705          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3706              {
3707              if (eptr >= md->end_subject)
3708                {
3709                SCHECK_PARTIAL();
3710                RRETURN(MATCH_NOMATCH);
3711                }
3712            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3713              }
3714          break;          break;
3715    
3716          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3717          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3718              {
3719              if (eptr >= md->end_subject)
3720                {
3721                SCHECK_PARTIAL();
3722                RRETURN(MATCH_NOMATCH);
3723                }
3724            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3725              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3726              }
3727          break;          break;
3728    
3729          case OP_WORDCHAR:          case OP_WORDCHAR:
3730          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3731              {
3732              if (eptr >= md->end_subject)
3733                {
3734                SCHECK_PARTIAL();
3735                RRETURN(MATCH_NOMATCH);
3736                }
3737            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3738              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3739              }
3740          break;          break;
3741    
3742          default:          default:
# Line 2723  for (;;) Line 3762  for (;;)
3762            case PT_ANY:            case PT_ANY:
3763            for (fi = min;; fi++)            for (fi = min;; fi++)
3764              {              {
3765              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3766              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3767              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3768                if (eptr >= md->end_subject)
3769                  {
3770                  SCHECK_PARTIAL();
3771                  RRETURN(MATCH_NOMATCH);
3772                  }
3773              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3774              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3775              }              }
3776            break;            /* Control never gets here */
3777    
3778            case PT_LAMP:            case PT_LAMP:
3779            for (fi = min;; fi++)            for (fi = min;; fi++)
3780              {              {
3781              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3782              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3783              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3784                if (eptr >= md->end_subject)
3785                  {
3786                  SCHECK_PARTIAL();
3787                  RRETURN(MATCH_NOMATCH);
3788                  }
3789              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3790              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3791              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3792                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3793                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3794                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3795              }              }
3796            break;            /* Control never gets here */
3797    
3798            case PT_GC:            case PT_GC:
3799            for (fi = min;; fi++)            for (fi = min;; fi++)
3800              {              {
3801              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3802              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3803              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3804                if (eptr >= md->end_subject)
3805                  {
3806                  SCHECK_PARTIAL();
3807                  RRETURN(MATCH_NOMATCH);
3808                  }
3809              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
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                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3813              }              }
3814            break;            /* Control never gets here */
3815    
3816            case PT_PC:            case PT_PC:
3817            for (fi = min;; fi++)            for (fi = min;; fi++)
3818              {              {
3819              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3820              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3821              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3822                if (eptr >= md->end_subject)
3823                  {
3824                  SCHECK_PARTIAL();
3825                  RRETURN(MATCH_NOMATCH);
3826                  }
3827              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3828              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3829              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3830                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3831              }              }
3832            break;            /* Control never gets here */
3833    
3834            case PT_SC:            case PT_SC:
3835            for (fi = min;; fi++)            for (fi = min;; fi++)
3836              {              {
3837              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3838              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3839              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3840                if (eptr >= md->end_subject)
3841                  {
3842                  SCHECK_PARTIAL();
3843                  RRETURN(MATCH_NOMATCH);
3844                  }
3845              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3846              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3847              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3848                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3849              }              }
3850            break;            /* Control never gets here */
3851    
3852            default:            default:
3853            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3854            }            }
3855          }          }
3856    
# Line 2798  for (;;) Line 3861  for (;;)
3861          {          {
3862          for (fi = min;; fi++)          for (fi = min;; fi++)
3863            {            {
3864            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3865            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3866            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3867              if (eptr >= md->end_subject)
3868                {
3869                SCHECK_PARTIAL();
3870                RRETURN(MATCH_NOMATCH);
3871                }
3872            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3873            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3874            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3875            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3876              {              {
3877              int len = 1;              int len = 1;
3878              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3879                {                else { GETCHARLEN(c, eptr, len); }
3880                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3881              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3882              eptr += len;              eptr += len;
3883              }              }
# Line 2827  for (;;) Line 3893  for (;;)
3893          {          {
3894          for (fi = min;; fi++)          for (fi = min;; fi++)
3895            {            {
3896            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3897            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3898            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3899              if (eptr >= md->end_subject)
3900                {
3901                SCHECK_PARTIAL();
3902                RRETURN(MATCH_NOMATCH);
3903                }
3904              if (ctype == OP_ANY && IS_NEWLINE(eptr))
3905                RRETURN(MATCH_NOMATCH);
3906            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3907            switch(ctype)            switch(ctype)
3908              {              {
3909              case OP_ANY:              case OP_ANY:        /* This is the non-NL case */
3910              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3911                case OP_ANYBYTE:
3912              break;              break;
3913    
3914              case OP_ANYBYTE:              case OP_ANYNL:
3915                switch(c)
3916                  {
3917                  default: RRETURN(MATCH_NOMATCH);
3918                  case 0x000d:
3919                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3920                  break;
3921                  case 0x000a:
3922                  break;
3923    
3924                  case 0x000b:
3925                  case 0x000c:
3926                  case 0x0085:
3927                  case 0x2028:
3928                  case 0x2029:
3929                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3930                  break;
3931                  }
3932                break;
3933    
3934                case OP_NOT_HSPACE:
3935                switch(c)
3936                  {
3937                  default: break;
3938                  case 0x09:      /* HT */
3939                  case 0x20:      /* SPACE */
3940                  case 0xa0:      /* NBSP */
3941                  case 0x1680:    /* OGHAM SPACE MARK */
3942                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3943                  case 0x2000:    /* EN QUAD */
3944                  case 0x2001:    /* EM QUAD */
3945                  case 0x2002:    /* EN SPACE */
3946                  case 0x2003:    /* EM SPACE */
3947                  case 0x2004:    /* THREE-PER-EM SPACE */
3948                  case 0x2005:    /* FOUR-PER-EM SPACE */
3949                  case 0x2006:    /* SIX-PER-EM SPACE */
3950                  case 0x2007:    /* FIGURE SPACE */
3951                  case 0x2008:    /* PUNCTUATION SPACE */
3952                  case 0x2009:    /* THIN SPACE */
3953                  case 0x200A:    /* HAIR SPACE */
3954                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3955                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3956                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3957                  RRETURN(MATCH_NOMATCH);
3958                  }
3959                break;
3960    
3961                case OP_HSPACE:
3962                switch(c)
3963                  {
3964                  default: RRETURN(MATCH_NOMATCH);
3965                  case 0x09:      /* HT */
3966                  case 0x20:      /* SPACE */
3967                  case 0xa0:      /* NBSP */
3968                  case 0x1680:    /* OGHAM SPACE MARK */
3969                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3970                  case 0x2000:    /* EN QUAD */
3971                  case 0x2001:    /* EM QUAD */
3972                  case 0x2002:    /* EN SPACE */
3973                  case 0x2003:    /* EM SPACE */
3974                  case 0x2004:    /* THREE-PER-EM SPACE */
3975                  case 0x2005:    /* FOUR-PER-EM SPACE */
3976                  case 0x2006:    /* SIX-PER-EM SPACE */
3977                  case 0x2007:    /* FIGURE SPACE */
3978                  case 0x2008:    /* PUNCTUATION SPACE */
3979                  case 0x2009:    /* THIN SPACE */
3980                  case 0x200A:    /* HAIR SPACE */
3981                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3982                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3983                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3984                  break;
3985                  }
3986                break;
3987    
3988                case OP_NOT_VSPACE:
3989                switch(c)
3990                  {
3991                  default: break;
3992                  case 0x0a:      /* LF */
3993                  case 0x0b:      /* VT */
3994                  case 0x0c:      /* FF */
3995                  case 0x0d:      /* CR */
3996                  case 0x85:      /* NEL */
3997                  case 0x2028:    /* LINE SEPARATOR */
3998                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3999                  RRETURN(MATCH_NOMATCH);
4000                  }
4001                break;
4002    
4003                case OP_VSPACE:
4004                switch(c)
4005                  {
4006                  default: RRETURN(MATCH_NOMATCH);
4007                  case 0x0a:      /* LF */
4008                  case 0x0b:      /* VT */
4009                  case 0x0c:      /* FF */
4010                  case 0x0d:      /* CR */
4011                  case 0x85:      /* NEL */
4012                  case 0x2028:    /* LINE SEPARATOR */
4013                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4014                  break;
4015                  }
4016              break;              break;
4017    
4018              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2866  for (;;) Line 4040  for (;;)
4040                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4041              break;              break;
4042    
4043              case OP_WORDCHAR:              case OP_WORDCHAR:
4044              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0)              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0)
4045                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4046                break;
4047    
4048                default:
4049                RRETURN(PCRE_ERROR_INTERNAL);
4050                }
4051              }
4052            }
4053          else
4054    #endif
4055          /* Not UTF-8 mode */
4056            {
4057            for (fi = min;; fi++)
4058              {
4059              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4060              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4061              if (fi >= max) RRETURN(MATCH_NOMATCH);
4062              if (eptr >= md->end_subject)
4063                {
4064                SCHECK_PARTIAL();
4065                RRETURN(MATCH_NOMATCH);
4066                }
4067              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4068                RRETURN(MATCH_NOMATCH);
4069              c = *eptr++;
4070              switch(ctype)
4071                {
4072                case OP_ANY:     /* This is the non-NL case */
4073                case OP_ALLANY:
4074                case OP_ANYBYTE:
4075                break;
4076    
4077                case OP_ANYNL:
4078                switch(c)
4079                  {
4080                  default: RRETURN(MATCH_NOMATCH);
4081                  case 0x000d:
4082                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4083                  break;
4084    
4085