/[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 85 by nigel, Sat Feb 24 21:41:13 2007 UTC revision 428 by ph10, Mon Aug 31 17:10:26 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-2005 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;  
   const uschar *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 128  Returns:      TRUE if matched Line 136  Returns:      TRUE if matched
136  */  */
137    
138  static BOOL  static BOOL
139  match_ref(int offset, register const uschar *eptr, int length, match_data *md,  match_ref(int offset, register USPTR eptr, int length, match_data *md,
140    unsigned long int ims)    unsigned long int ims)
141  {  {
142  const uschar *p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
143    
144  #ifdef DEBUG  #ifdef DEBUG
145  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
# 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 169  return TRUE; Line 203  return TRUE;
203  ****************************************************************************  ****************************************************************************
204                     RECURSION IN THE match() FUNCTION                     RECURSION IN THE match() FUNCTION
205    
206  The match() function is highly recursive. Some regular expressions can cause  The match() function is highly recursive, though not every recursive call
207  it to recurse thousands of times. I was writing for Unix, so I just let it  increases the recursive depth. Nevertheless, some regular expressions can cause
208  call itself recursively. This uses the stack for saving everything that has  it to recurse to a great depth. I was writing for Unix, so I just let it call
209  to be saved for a recursive call. On Unix, the stack can be large, and this  itself recursively. This uses the stack for saving everything that has to be
210  works fine.  saved for a recursive call. On Unix, the stack can be large, and this works
211    fine.
212  It turns out that on non-Unix systems there are problems with programs that  
213  use a lot of stack. (This despite the fact that every last chip has oodles  It turns out that on some non-Unix-like systems there are problems with
214  of memory these days, and techniques for extending the stack have been known  programs that use a lot of stack. (This despite the fact that every last chip
215  for decades.) So....  has oodles of memory these days, and techniques for extending the stack have
216    been known for decades.) So....
217    
218  There is a fudge, triggered by defining NO_RECURSE, which avoids recursive  There is a fudge, triggered by defining NO_RECURSE, which avoids recursive
219  calls by keeping local variables that need to be preserved in blocks of memory  calls by keeping local variables that need to be preserved in blocks of memory
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  /* These versions of the macros use the stack, as normal */  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
251    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  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) rx = match(ra,rb,rc,rd,re,rf,rg)  
257    #ifdef DEBUG
258    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259      { \
260      printf("match() called in line %d\n", __LINE__); \
261      rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262      printf("to line %d\n", __LINE__); \
263      }
264    #define RRETURN(ra) \
265      { \
266      printf("match() returned %d from line %d ", ra, __LINE__); \
267      return ra; \
268      }
269    #else
270    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271      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
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->Xprevframe = frame;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      frame = newframe;\    newframe->Xprevframe = frame;\
297      DPRINTF(("restarting from line %d\n", __LINE__));\    frame = newframe;\
298      goto HEAP_RECURSE;\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      }\    goto HEAP_RECURSE;\
300    else\    L_##rw:\
301      {\    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 235  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 250  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      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;
353    
354  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
355    int Xprop_type;    int Xprop_type;
356      int Xprop_value;
357    int Xprop_fail_result;    int Xprop_fail_result;
358    int Xprop_category;    int Xprop_category;
359    int Xprop_chartype;    int Xprop_chartype;
360    int Xprop_othercase;    int Xprop_script;
361    int Xprop_test_against;    int Xoclength;
362    int *Xprop_test_variable;    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 301  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 320  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 && eptr >= md->end_subject && eptr > mstart)\
412        {\
413        md->hitend = TRUE;\
414        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415        }
416    
417    #define SCHECK_PARTIAL()\
418      if (md->partial && eptr > mstart)\
419        {\
420        md->hitend = TRUE;\
421        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422        }
423    
424  Performance note: It might be tempting to extract commonly used fields from the  
425  md structure (e.g. utf8, end_subject) into individual variables to improve  /* 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 342  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
445    
446  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
447                 MATCH_NOMATCH if failed to match  )                 MATCH_NOMATCH if failed to match  )
448                 a negative PCRE_ERROR_xxx value if aborted by an error condition                 a negative PCRE_ERROR_xxx value if aborted by an error condition
449                   (e.g. stopped by recursion limit)                   (e.g. stopped by repeated call or recursion limit)
450  */  */
451    
452  static int  static int
453  match(REGISTER const uschar *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 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 */
462    register int  i;           /* Used for loops not involving calls to RMATCH() */
463    register unsigned int c;   /* Character values not kept over RMATCH() calls */
464    register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
465    
466  register int  rrc;    /* Returns from recursive calls */  BOOL minimize, possessive; /* Quantifier options */
467  register int  i;      /* Used for loops not involving calls to RMATCH() */  int condcode;
 register int  c;      /* Character values not kept over RMATCH() calls */  
 register BOOL utf8;   /* Local copy of UTF-8 flag for speed */  
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 377  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;
486  frame->Xflags = flags;  frame->Xflags = flags;
487    frame->Xrdepth = rdepth;
488    
489  /* This is where control jumps back to to effect "recursion" */  /* This is where control jumps back to to effect "recursion" */
490    
# Line 390  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
501  #define flags              frame->Xflags  #define flags              frame->Xflags
502    #define rdepth             frame->Xrdepth
503    
504  /* Ditto for the local variables */  /* Ditto for the local variables */
505    
# Line 401  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 411  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
524    
525  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
526  #define prop_type          frame->Xprop_type  #define prop_type          frame->Xprop_type
527    #define prop_value         frame->Xprop_value
528  #define prop_fail_result   frame->Xprop_fail_result  #define prop_fail_result   frame->Xprop_fail_result
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_othercase     frame->Xprop_othercase  #define prop_script        frame->Xprop_script
532  #define prop_test_against  frame->Xprop_test_against  #define oclength           frame->Xoclength
533  #define prop_test_variable frame->Xprop_test_variable  #define occhars            frame->Xocchars
534  #endif  #endif
535    
536  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 447  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    
561    
562  #ifdef SUPPORT_UTF8                /* Many of these variables are used ony */  #ifdef SUPPORT_UTF8                /* Many of these variables are used only  */
563  const uschar *charptr;             /* small blocks of the code. My normal  */  const uschar *charptr;             /* in small blocks of the code. My normal */
564  #endif                             /* style of coding would have declared  */  #endif                             /* style of coding would have declared    */
565  const uschar *callpat;             /* them within each of those blocks.    */  const uschar *callpat;             /* them within each of those blocks.      */
566  const uschar *data;                /* However, in order to accommodate the */  const uschar *data;                /* However, in order to accommodate the   */
567  const uschar *next;                /* version of this code that uses an    */  const uschar *next;                /* version of this code that uses an      */
568  const uschar *pp;                  /* external "stack" implemented on the  */  USPTR         pp;                  /* external "stack" implemented on the    */
569  const uschar *prev;                /* heap, it is easier to declare them   */  const uschar *prev;                /* heap, it is easier to declare them all */
570  const uschar *saved_eptr;          /* all here, so the declarations can    */  USPTR         saved_eptr;          /* here, so the declarations can be cut   */
571                                     /* be cut out in a block. The only      */                                     /* out in a block. The only declarations  */
572  recursion_info new_recursive;      /* declarations within blocks below are */  recursion_info new_recursive;      /* within blocks below are for variables  */
573                                     /* for variables that do not have to    */                                     /* that do not have to be preserved over  */
574  BOOL cur_is_word;                  /* be preserved over a recursive call   */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
575  BOOL condition;                    /* to RMATCH().                         */  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;
579    
580  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
581  int prop_type;  int prop_type;
582    int prop_value;
583  int prop_fail_result;  int prop_fail_result;
584  int prop_category;  int prop_category;
585  int prop_chartype;  int prop_chartype;
586  int prop_othercase;  int prop_script;
587  int prop_test_against;  int oclength;
588  int *prop_test_variable;  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 493  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. */
608    
609  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
610    prop_value = 0;
611  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_against = 0;  
 prop_test_variable = NULL;  
612  #endif  #endif
613    
614  /* OK, now we can get on with the real code of the function. Recursion is  
615  specified by the macros RMATCH and RRETURN. When NO_RECURSE is *not* defined,  /* This label is used for tail recursion, which is used in a few cases even
616  these just turn into a recursive call to match() and a "return", respectively.  when NO_RECURSE is not defined, in order to reduce the amount of stack that is
617  However, RMATCH isn't like a function call because it's quite a complicated  used. Thanks to Ian Taylor for noticing this possibility and sending the
618  macro. It has to be used in one particular way. This shouldn't, however, impact  original patch. */
619  performance when true recursion is being used. */  
620    TAIL_RECURSE:
621    
622    /* 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
624    NO_RECURSE is *not* defined, these just turn into a recursive call to match()
625    and a "return", respectively (possibly with some debugging if DEBUG is
626    defined). However, RMATCH isn't like a function call because it's quite a
627    complicated macro. It has to be used in one particular way. This shouldn't,
628    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
637    haven't exceeded the recursive call limit. */
638    
639  if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);  if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);
640    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;
666    minimize = FALSE;  
667      switch(op)
   /* 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. */  
   
   if (op > OP_BRA)  
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 584  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 603  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        {        {
922        recursion_info *rec = md->recursive;        recursion_info *rec = md->recursive;
923        DPRINTF(("Hit the end in a (?0) recursion\n"));        DPRINTF(("End of pattern in a (?0) recursion\n"));
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;        mstart = rec->save_start;
928        ims = original_ims;        ims = original_ims;
929        ecode = rec->after_call;        ecode = rec->after_call;
930        break;        break;
# Line 694  for (;;) Line 933  for (;;)
933      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
934      string - backtracking will then try other alternatives, if any. */      string - backtracking will then try other alternatives, if any. */
935    
936      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
937      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
938      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
939        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
940      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
941    
942      /* Change option settings */      /* Change option settings */
# Line 717  for (;;) Line 957  for (;;)
957      case OP_ASSERTBACK:      case OP_ASSERTBACK:
958      do      do
959        {        {
960        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
961          match_isgroup);          RM4);
962        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
963        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
964        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
965        }        }
966      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 744  for (;;) Line 984  for (;;)
984      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
985      do      do
986        {        {
987        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
988          match_isgroup);          RM5);
989        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
990        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
991        ecode += GET(ecode,1);        ecode += GET(ecode,1);
992        }        }
993      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 766  for (;;) Line 1006  for (;;)
1006  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1007      if (utf8)      if (utf8)
1008        {        {
1009        c = GET(ecode,1);        i = GET(ecode, 1);
1010        for (i = 0; i < c; i++)        while (i-- > 0)
1011          {          {
1012          eptr--;          eptr--;
1013          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1014          BACKCHAR(eptr)          BACKCHAR(eptr);
1015          }          }
1016        }        }
1017      else      else
# Line 780  for (;;) Line 1020  for (;;)
1020      /* 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 */
1021    
1022        {        {
1023        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1024        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1025        }        }
1026    
# Line 800  for (;;) Line 1040  for (;;)
1040        cb.version          = 1;   /* Version 1 of the callout block */        cb.version          = 1;   /* Version 1 of the callout block */
1041        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1042        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1043        cb.subject          = (const char *)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1044        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1045        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1046        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1047        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1048        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 837  for (;;) Line 1077  for (;;)
1077      case OP_RECURSE:      case OP_RECURSE:
1078        {        {
1079        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1080        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1081            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);  
1082    
1083        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1084    
# Line 869  for (;;) Line 1104  for (;;)
1104    
1105        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1106              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1107        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1108        md->start_match = eptr;        mstart = eptr;
1109    
1110        /* 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
1111        restore the offset and recursion data. */        restore the offset and recursion data. */
1112    
1113        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1114          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1115        do        do
1116          {          {
1117          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1118              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1119          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1120            {            {
1121              DPRINTF(("Recursion matched\n"));
1122            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1123            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1124              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1125            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1126            }            }
1127          else if (rrc != MATCH_NOMATCH) RRETURN(rrc);          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1128              {
1129              DPRINTF(("Recursion gave error %d\n", rrc));
1130              if (new_recursive.offset_save != stacksave)
1131                (pcre_free)(new_recursive.offset_save);
1132              RRETURN(rrc);
1133              }
1134    
1135          md->recursive = &new_recursive;          md->recursive = &new_recursive;
1136          memcpy(md->offset_vector, new_recursive.offset_save,          memcpy(md->offset_vector, new_recursive.offset_save,
# Line 912  for (;;) Line 1155  for (;;)
1155      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer. */
1156    
1157      case OP_ONCE:      case OP_ONCE:
1158        {      prev = ecode;
1159        prev = ecode;      saved_eptr = eptr;
       saved_eptr = eptr;  
1160    
1161        do      do
1162          {        {
1163          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1164            eptrb, match_isgroup);        if (rrc == MATCH_MATCH) break;
1165          if (rrc == MATCH_MATCH) break;        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1166          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        ecode += GET(ecode,1);
1167          ecode += GET(ecode,1);        }
1168          }      while (*ecode == OP_ALT);
       while (*ecode == OP_ALT);  
1169    
1170        /* If hit the end of the group (which could be repeated), fail */      /* If hit the end of the group (which could be repeated), fail */
1171    
1172        if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1173    
1174        /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1175        mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1176    
1177        do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1178    
1179        offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1180        eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
1181    
1182        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1183        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.
1184        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1185        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
1186        course of events. */      course of events. */
1187    
1188        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1189          {        {
1190          ecode += 1+LINK_SIZE;        ecode += 1+LINK_SIZE;
1191          break;        break;
1192          }        }
1193    
1194        /* 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
1195        preceding bracket, in the appropriate order. We need to reset any options      preceding bracket, in the appropriate order. The second "call" of match()
1196        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
1197        opcode. */      any options that changed within the bracket before re-running it, so
1198        check the next opcode. */
1199    
1200        if (ecode[1+LINK_SIZE] == OP_OPT)      if (ecode[1+LINK_SIZE] == OP_OPT)
1201          {        {
1202          ims = (ims & ~PCRE_IMS) | ecode[4];        ims = (ims & ~PCRE_IMS) | ecode[4];
1203          DPRINTF(("ims set to %02lx at group repeat\n", ims));        DPRINTF(("ims set to %02lx at group repeat\n", ims));
1204          }        }
1205    
1206        if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1207          {        {
1208          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);
1209          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1210          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        ecode = prev;
1211          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        flags = 0;
1212          }        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);  
         }  
1213        }        }
1214      RRETURN(MATCH_NOMATCH);      else  /* OP_KETRMAX */
1215          {
1216          RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1217          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1218          ecode += 1 + LINK_SIZE;
1219          flags = 0;
1220          goto TAIL_RECURSE;
1221          }
1222        /* Control never gets here */
1223    
1224      /* 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
1225      bracketed group and go to there. */      bracketed group and go to there. */
# Line 985  for (;;) Line 1228  for (;;)
1228      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1229      break;      break;
1230    
1231      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1232      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
1233      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
1234      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
1235      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1236    
1237      case OP_BRAZERO:      case OP_BRAZERO:
1238        {        {
1239        next = ecode+1;        next = ecode+1;
1240        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1241        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1242        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1243        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1244        }        }
1245      break;      break;
1246    
1247      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1248        {        {
1249        next = ecode+1;        next = ecode+1;
1250        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1251        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);  
1252        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1253        ecode++;        ecode++;
1254        }        }
1255      break;      break;
1256    
1257      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1258      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1259      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1260      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1261          ecode = next + 1 + LINK_SIZE;
1262          }
1263        break;
1264    
1265        /* End of a group, repeated or non-repeating. */
1266    
1267      case OP_KET:      case OP_KET:
1268      case OP_KETRMIN:      case OP_KETRMIN:
1269      case OP_KETRMAX:      case OP_KETRMAX:
1270        {      prev = ecode - GET(ecode, 1);
       prev = ecode - GET(ecode, 1);  
       saved_eptr = eptrb->epb_saved_eptr;  
   
       /* Back up the stack of bracket start pointers. */  
1271    
1272        eptrb = eptrb->epb_prev;      /* If this was a group that remembered the subject start, in order to break
1273        infinite repeats of empty string matches, retrieve the subject start from
1274        the chain. Otherwise, set it NULL. */
1275    
1276        if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev >= OP_SBRA)
1277            *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||        {
1278            *prev == OP_ONCE)        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1279          {        eptrb = eptrb->epb_prev;              /* Backup to previous group */
1280          md->end_match_ptr = eptr;      /* For ONCE */        }
1281          md->end_offset_top = offset_top;      else saved_eptr = NULL;
         RRETURN(MATCH_MATCH);  
         }  
1282    
1283        /* In all other cases except a conditional group we have to check the      /* If we are at the end of an assertion group, stop matching and return
1284        group number back at the start and if necessary complete handling an      MATCH_MATCH, but record the current high water mark for use by positive
1285        extraction by setting the offsets and bumping the high water mark. */      assertions. Do this also for the "once" (atomic) groups. */
1286    
1287        if (*prev != OP_COND)      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1288          {          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1289          number = *prev - OP_BRA;          *prev == OP_ONCE)
1290          {
1291          md->end_match_ptr = eptr;      /* For ONCE */
1292          md->end_offset_top = offset_top;
1293          RRETURN(MATCH_MATCH);
1294          }
1295    
1296          /* For extended extraction brackets (large number), we have to fish out      /* For capturing groups we have to check the group number back at the start
1297          the number from a dummy opcode at the start. */      and if necessary complete handling an extraction by setting the offsets and
1298        bumping the high water mark. Note that whole-pattern recursion is coded as
1299        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1300        when the OP_END is reached. Other recursion is handled here. */
1301    
1302          if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1303          offset = number << 1;        {
1304          number = GET2(prev, 1+LINK_SIZE);
1305          offset = number << 1;
1306    
1307  #ifdef DEBUG  #ifdef DEBUG
1308          printf("end bracket %d", number);        printf("end bracket %d", number);
1309          printf("\n");        printf("\n");
1310  #endif  #endif
1311    
1312          /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1313          of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1314          into group 0, so it won't be picked up here. Instead, we catch it when          {
1315          the OP_END is reached. */          md->offset_vector[offset] =
1316              md->offset_vector[md->offset_end - number];
1317          if (number > 0)          md->offset_vector[offset+1] = eptr - md->start_subject;
1318            {          if (offset_top <= offset) offset_top = offset + 2;
1319            md->capture_last = number;          }
1320            if (offset >= md->offset_max) md->offset_overflow = TRUE; else  
1321              {        /* Handle a recursively called group. Restore the offsets
1322              md->offset_vector[offset] =        appropriately and continue from after the call. */
1323                md->offset_vector[md->offset_end - number];  
1324              md->offset_vector[offset+1] = eptr - md->start_subject;        if (md->recursive != NULL && md->recursive->group_num == number)
1325              if (offset_top <= offset) offset_top = offset + 2;          {
1326              }          recursion_info *rec = md->recursive;
1327            DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1328            /* Handle a recursively called group. Restore the offsets          md->recursive = rec->prevrec;
1329            appropriately and continue from after the call. */          mstart = rec->save_start;
1330            memcpy(md->offset_vector, rec->offset_save,
1331            if (md->recursive != NULL && md->recursive->group_num == number)            rec->saved_max * sizeof(int));
1332              {          ecode = rec->after_call;
1333              recursion_info *rec = md->recursive;          ims = original_ims;
1334              DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          break;
             md->recursive = rec->prevrec;  
             md->start_match = rec->save_start;  
             memcpy(md->offset_vector, rec->offset_save,  
               rec->saved_max * sizeof(int));  
             ecode = rec->after_call;  
             ims = original_ims;  
             break;  
             }  
           }  
1335          }          }
1336          }
1337    
1338        /* 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
1339        the group. */      flags, in case they got changed during the group. */
1340    
1341        ims = original_ims;      ims = original_ims;
1342        DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
1343    
1344        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1345        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.
1346        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1347        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
1348        course of events. */      course of events. */
1349    
1350        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1351          {        {
1352          ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1353          break;        break;
1354          }        }
1355    
1356        /* 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
1357        preceding bracket, in the appropriate order. */      preceding bracket, in the appropriate order. In the second case, we can use
1358        tail recursion to avoid using another stack frame, unless we have an
1359        unlimited repeat of a group that can match an empty string. */
1360    
1361        if (*ecode == OP_KETRMIN)      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1362          {  
1363          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);      if (*ecode == OP_KETRMIN)
1364          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        {
1365          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1366          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1367          }        if (flags != 0)    /* Could match an empty string */
       else  /* OP_KETRMAX */  
1368          {          {
1369          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1370          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);  
1371          }          }
1372          ecode = prev;
1373          goto TAIL_RECURSE;
1374        }        }
1375        else  /* OP_KETRMAX */
1376      RRETURN(MATCH_NOMATCH);        {
1377          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1378          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1379          ecode += 1 + LINK_SIZE;
1380          flags = 0;
1381          goto TAIL_RECURSE;
1382          }
1383        /* Control never gets here */
1384    
1385      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1386    
# Line 1135  for (;;) Line 1388  for (;;)
1388      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1389      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1390        {        {
1391        if (eptr != md->start_subject && eptr[-1] != NEWLINE)        if (eptr != md->start_subject &&
1392              (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1393          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1394        ecode++;        ecode++;
1395        break;        break;
# Line 1156  for (;;) Line 1410  for (;;)
1410      ecode++;      ecode++;
1411      break;      break;
1412    
1413        /* Reset the start of match point */
1414    
1415        case OP_SET_SOM:
1416        mstart = eptr;
1417        ecode++;
1418        break;
1419    
1420      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1421      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. */
1422    
# Line 1163  for (;;) Line 1424  for (;;)
1424      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1425        {        {
1426        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1427          { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
1428        else        else
1429          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) RRETURN(MATCH_NOMATCH); }
1430        ecode++;        ecode++;
# Line 1174  for (;;) Line 1435  for (;;)
1435        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
1436        if (!md->endonly)        if (!md->endonly)
1437          {          {
1438          if (eptr < md->end_subject - 1 ||          if (eptr != md->end_subject &&
1439             (eptr == md->end_subject - 1 && *eptr != NEWLINE))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1440            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1441          ecode++;          ecode++;
1442          break;          break;
1443          }          }
1444        }        }
1445      /* ... else fall through */      /* ... else fall through for endonly */
1446    
1447      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1448    
# Line 1193  for (;;) Line 1454  for (;;)
1454      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1455    
1456      case OP_EODN:      case OP_EODN:
1457      if (eptr < md->end_subject - 1 ||      if (eptr != md->end_subject &&
1458         (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1459          RRETURN(MATCH_NOMATCH);
1460      ecode++;      ecode++;
1461      break;      break;
1462    
# Line 1213  for (;;) Line 1475  for (;;)
1475          {          {
1476          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1477            {            {
1478            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1479            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1480            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1481            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1482            }            }
1483          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1484              {
1485              SCHECK_PARTIAL();
1486              cur_is_word = FALSE;
1487              }
1488            else
1489            {            {
1490            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1491            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1227  for (;;) Line 1494  for (;;)
1494        else        else
1495  #endif  #endif
1496    
1497        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1498    
1499          {          {
1500          prev_is_word = (eptr != md->start_subject) &&          prev_is_word = (eptr != md->start_subject) &&
1501            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1502          cur_is_word = (eptr < md->end_subject) &&          if (eptr >= md->end_subject)
1503            ((md->ctypes[*eptr] & ctype_word) != 0);            {
1504              SCHECK_PARTIAL();
1505              cur_is_word = FALSE;
1506              }
1507            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1508          }          }
1509    
1510        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1247  for (;;) Line 1518  for (;;)
1518      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1519    
1520      case OP_ANY:      case OP_ANY:
1521      if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1522        /* Fall through */
1523    
1524        case OP_ALLANY:
1525        if (eptr++ >= md->end_subject)
1526          {
1527          SCHECK_PARTIAL();
1528        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1529      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);        }
1530  #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  
1531      ecode++;      ecode++;
1532      break;      break;
1533    
# Line 1261  for (;;) Line 1535  for (;;)
1535      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1536    
1537      case OP_ANYBYTE:      case OP_ANYBYTE:
1538      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1539          {
1540          SCHECK_PARTIAL();
1541          RRETURN(MATCH_NOMATCH);
1542          }
1543      ecode++;      ecode++;
1544      break;      break;
1545    
1546      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1547      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1548          {
1549          SCHECK_PARTIAL();
1550          RRETURN(MATCH_NOMATCH);
1551          }
1552      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1553      if (      if (
1554  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1279  for (;;) Line 1561  for (;;)
1561      break;      break;
1562    
1563      case OP_DIGIT:      case OP_DIGIT:
1564      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1565          {
1566          SCHECK_PARTIAL();
1567          RRETURN(MATCH_NOMATCH);
1568          }
1569      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1570      if (      if (
1571  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1292  for (;;) Line 1578  for (;;)
1578      break;      break;
1579    
1580      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1581      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1582          {
1583          SCHECK_PARTIAL();
1584          RRETURN(MATCH_NOMATCH);
1585          }
1586      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1587      if (      if (
1588  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1305  for (;;) Line 1595  for (;;)
1595      break;      break;
1596    
1597      case OP_WHITESPACE:      case OP_WHITESPACE:
1598      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1599          {
1600          SCHECK_PARTIAL();
1601          RRETURN(MATCH_NOMATCH);
1602          }
1603      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1604      if (      if (
1605  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1318  for (;;) Line 1612  for (;;)
1612      break;      break;
1613    
1614      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1615      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1616          {
1617          SCHECK_PARTIAL();
1618          RRETURN(MATCH_NOMATCH);
1619          }
1620      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1621      if (      if (
1622  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1331  for (;;) Line 1629  for (;;)
1629      break;      break;
1630    
1631      case OP_WORDCHAR:      case OP_WORDCHAR:
1632      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1633          {
1634          SCHECK_PARTIAL();
1635          RRETURN(MATCH_NOMATCH);
1636          }
1637      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1638      if (      if (
1639  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1343  for (;;) Line 1645  for (;;)
1645      ecode++;      ecode++;
1646      break;      break;
1647    
1648  #ifdef SUPPORT_UCP      case OP_ANYNL:
1649      /* Check the next character by Unicode property. We will get here only      if (eptr >= md->end_subject)
1650      if the support is in the binary; otherwise a compile-time error occurs. */        {
1651          SCHECK_PARTIAL();
1652      case OP_PROP:        RRETURN(MATCH_NOMATCH);
1653      case OP_NOTPROP:        }
     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);  
1654      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1655        switch(c)
1656        {        {
1657        int chartype, rqdtype;        default: RRETURN(MATCH_NOMATCH);
1658        int othercase;        case 0x000d:
1659        int category = _pcre_ucp_findchar(c, &chartype, &othercase);        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1660          break;
1661    
1662        rqdtype = *(++ecode);        case 0x000a:
1663        ecode++;        break;
1664    
1665        if (rqdtype >= 128)        case 0x000b:
1666          {        case 0x000c:
1667          if ((rqdtype - 128 != category) == (op == OP_PROP))        case 0x0085:
1668            RRETURN(MATCH_NOMATCH);        case 0x2028:
1669          }        case 0x2029:
1670        else        if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1671          {        break;
         if ((rqdtype != chartype) == (op == OP_PROP))  
           RRETURN(MATCH_NOMATCH);  
         }  
1672        }        }
1673        ecode++;
1674      break;      break;
1675    
1676      /* Match an extended Unicode sequence. We will get here only if the support      case OP_NOT_HSPACE:
1677      is in the binary; otherwise a compile-time error occurs. */      if (eptr >= md->end_subject)
   
     case OP_EXTUNI:  
     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);  
     GETCHARINCTEST(c, eptr);  
1678        {        {
1679        int chartype;        SCHECK_PARTIAL();
1680        int othercase;        RRETURN(MATCH_NOMATCH);
1681        int category = _pcre_ucp_findchar(c, &chartype, &othercase);        }
1682        GETCHARINCTEST(c, eptr);
1683        switch(c)
1684          {
1685          default: break;
1686          case 0x09:      /* HT */
1687          case 0x20:      /* SPACE */
1688          case 0xa0:      /* NBSP */
1689          case 0x1680:    /* OGHAM SPACE MARK */
1690          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1691          case 0x2000:    /* EN QUAD */
1692          case 0x2001:    /* EM QUAD */
1693          case 0x2002:    /* EN SPACE */
1694          case 0x2003:    /* EM SPACE */
1695          case 0x2004:    /* THREE-PER-EM SPACE */
1696          case 0x2005:    /* FOUR-PER-EM SPACE */
1697          case 0x2006:    /* SIX-PER-EM SPACE */
1698          case 0x2007:    /* FIGURE SPACE */
1699          case 0x2008:    /* PUNCTUATION SPACE */
1700          case 0x2009:    /* THIN SPACE */
1701          case 0x200A:    /* HAIR SPACE */
1702          case 0x202f:    /* NARROW NO-BREAK SPACE */
1703          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1704          case 0x3000:    /* IDEOGRAPHIC SPACE */
1705          RRETURN(MATCH_NOMATCH);
1706          }
1707        ecode++;
1708        break;
1709    
1710        case OP_HSPACE:
1711        if (eptr >= md->end_subject)
1712          {
1713          SCHECK_PARTIAL();
1714          RRETURN(MATCH_NOMATCH);
1715          }
1716        GETCHARINCTEST(c, eptr);
1717        switch(c)
1718          {
1719          default: RRETURN(MATCH_NOMATCH);
1720          case 0x09:      /* HT */
1721          case 0x20:      /* SPACE */
1722          case 0xa0:      /* NBSP */
1723          case 0x1680:    /* OGHAM SPACE MARK */
1724          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1725          case 0x2000:    /* EN QUAD */
1726          case 0x2001:    /* EM QUAD */
1727          case 0x2002:    /* EN SPACE */
1728          case 0x2003:    /* EM SPACE */
1729          case 0x2004:    /* THREE-PER-EM SPACE */
1730          case 0x2005:    /* FOUR-PER-EM SPACE */
1731          case 0x2006:    /* SIX-PER-EM SPACE */
1732          case 0x2007:    /* FIGURE SPACE */
1733          case 0x2008:    /* PUNCTUATION SPACE */
1734          case 0x2009:    /* THIN SPACE */
1735          case 0x200A:    /* HAIR SPACE */
1736          case 0x202f:    /* NARROW NO-BREAK SPACE */
1737          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1738          case 0x3000:    /* IDEOGRAPHIC SPACE */
1739          break;
1740          }
1741        ecode++;
1742        break;
1743    
1744        case OP_NOT_VSPACE:
1745        if (eptr >= md->end_subject)
1746          {
1747          SCHECK_PARTIAL();
1748          RRETURN(MATCH_NOMATCH);
1749          }
1750        GETCHARINCTEST(c, eptr);
1751        switch(c)
1752          {
1753          default: break;
1754          case 0x0a:      /* LF */
1755          case 0x0b:      /* VT */
1756          case 0x0c:      /* FF */
1757          case 0x0d:      /* CR */
1758          case 0x85:      /* NEL */
1759          case 0x2028:    /* LINE SEPARATOR */
1760          case 0x2029:    /* PARAGRAPH SEPARATOR */
1761          RRETURN(MATCH_NOMATCH);
1762          }
1763        ecode++;
1764        break;
1765    
1766        case OP_VSPACE:
1767        if (eptr >= md->end_subject)
1768          {
1769          SCHECK_PARTIAL();
1770          RRETURN(MATCH_NOMATCH);
1771          }
1772        GETCHARINCTEST(c, eptr);
1773        switch(c)
1774          {
1775          default: RRETURN(MATCH_NOMATCH);
1776          case 0x0a:      /* LF */
1777          case 0x0b:      /* VT */
1778          case 0x0c:      /* FF */
1779          case 0x0d:      /* CR */
1780          case 0x85:      /* NEL */
1781          case 0x2028:    /* LINE SEPARATOR */
1782          case 0x2029:    /* PARAGRAPH SEPARATOR */
1783          break;
1784          }
1785        ecode++;
1786        break;
1787    
1788    #ifdef SUPPORT_UCP
1789        /* Check the next character by Unicode property. We will get here only
1790        if the support is in the binary; otherwise a compile-time error occurs. */
1791    
1792        case OP_PROP:
1793        case OP_NOTPROP:
1794        if (eptr >= md->end_subject)
1795          {
1796          SCHECK_PARTIAL();
1797          RRETURN(MATCH_NOMATCH);
1798          }
1799        GETCHARINCTEST(c, eptr);
1800          {
1801          const ucd_record *prop = GET_UCD(c);
1802    
1803          switch(ecode[1])
1804            {
1805            case PT_ANY:
1806            if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
1807            break;
1808    
1809            case PT_LAMP:
1810            if ((prop->chartype == ucp_Lu ||
1811                 prop->chartype == ucp_Ll ||
1812                 prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1813              RRETURN(MATCH_NOMATCH);
1814             break;
1815    
1816            case PT_GC:
1817            if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1818              RRETURN(MATCH_NOMATCH);
1819            break;
1820    
1821            case PT_PC:
1822            if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1823              RRETURN(MATCH_NOMATCH);
1824            break;
1825    
1826            case PT_SC:
1827            if ((ecode[2] != prop->script) == (op == OP_PROP))
1828              RRETURN(MATCH_NOMATCH);
1829            break;
1830    
1831            default:
1832            RRETURN(PCRE_ERROR_INTERNAL);
1833            }
1834    
1835          ecode += 3;
1836          }
1837        break;
1838    
1839        /* Match an extended Unicode sequence. We will get here only if the support
1840        is in the binary; otherwise a compile-time error occurs. */
1841    
1842        case OP_EXTUNI:
1843        if (eptr >= md->end_subject)
1844          {
1845          SCHECK_PARTIAL();
1846          RRETURN(MATCH_NOMATCH);
1847          }
1848        GETCHARINCTEST(c, eptr);
1849          {
1850          int category = UCD_CATEGORY(c);
1851        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1852        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1853          {          {
# Line 1390  for (;;) Line 1856  for (;;)
1856            {            {
1857            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1858            }            }
1859          category = _pcre_ucp_findchar(c, &chartype, &othercase);          category = UCD_CATEGORY(c);
1860          if (category != ucp_M) break;          if (category != ucp_M) break;
1861          eptr += len;          eptr += len;
1862          }          }
# Line 1411  for (;;) Line 1877  for (;;)
1877      case OP_REF:      case OP_REF:
1878        {        {
1879        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1880        ecode += 3;                                 /* Advance past item */        ecode += 3;
1881    
1882          /* If the reference is unset, there are two possibilities:
1883    
1884        /* If the reference is unset, set the length to be longer than the amount        (a) In the default, Perl-compatible state, set the length to be longer
1885        of subject left; this ensures that every attempt at a match fails. We        than the amount of subject left; this ensures that every attempt at a
1886        can't just fail here, because of the possibility of quantifiers with zero        match fails. We can't just fail here, because of the possibility of
1887        minima. */        quantifiers with zero minima.
1888    
1889        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        (b) If the JavaScript compatibility flag is set, set the length to zero
1890          md->end_subject - eptr + 1 :        so that the back reference matches an empty string.
1891          md->offset_vector[offset+1] - md->offset_vector[offset];  
1892          Otherwise, set the length to the length of what was matched by the
1893          referenced subpattern. */
1894    
1895          if (offset >= offset_top || md->offset_vector[offset] < 0)
1896            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1897          else
1898            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1899    
1900        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1901    
# Line 1449  for (;;) Line 1924  for (;;)
1924          break;          break;
1925    
1926          default:               /* No repeat follows */          default:               /* No repeat follows */
1927          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1928              {
1929              CHECK_PARTIAL();
1930              RRETURN(MATCH_NOMATCH);
1931              }
1932          eptr += length;          eptr += length;
1933          continue;              /* With the main loop */          continue;              /* With the main loop */
1934          }          }
1935    
1936        /* If the length of the reference is zero, just continue with the        /* If the length of the reference is zero, just continue with the
1937        main loop. */        main loop. */
1938    
1939        if (length == 0) continue;        if (length == 0) continue;
1940    
1941        /* First, ensure the minimum number of matches are present. We get back        /* First, ensure the minimum number of matches are present. We get back
# Line 1465  for (;;) Line 1944  for (;;)
1944    
1945        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
1946          {          {
1947          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1948              {
1949              CHECK_PARTIAL();
1950              RRETURN(MATCH_NOMATCH);
1951              }
1952          eptr += length;          eptr += length;
1953          }          }
1954    
# Line 1480  for (;;) Line 1963  for (;;)
1963          {          {
1964          for (fi = min;; fi++)          for (fi = min;; fi++)
1965            {            {
1966            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1967            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1968            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
1969              if (!match_ref(offset, eptr, length, md, ims))
1970                {
1971                CHECK_PARTIAL();
1972              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
1973                }
1974            eptr += length;            eptr += length;
1975            }            }
1976          /* Control never gets here */          /* Control never gets here */
# Line 1501  for (;;) Line 1988  for (;;)
1988            }            }
1989          while (eptr >= pp)          while (eptr >= pp)
1990            {            {
1991            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1992            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1993            eptr -= length;            eptr -= length;
1994            }            }
# Line 1510  for (;;) Line 1997  for (;;)
1997        }        }
1998      /* Control never gets here */      /* Control never gets here */
1999    
   
   
2000      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2001      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,
2002      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 1566  for (;;) Line 2051  for (;;)
2051          {          {
2052          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2053            {            {
2054            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2055                {
2056                SCHECK_PARTIAL();
2057                RRETURN(MATCH_NOMATCH);
2058                }
2059            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2060            if (c > 255)            if (c > 255)
2061              {              {
# Line 1584  for (;;) Line 2073  for (;;)
2073          {          {
2074          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2075            {            {
2076            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2077                {
2078                SCHECK_PARTIAL();
2079                RRETURN(MATCH_NOMATCH);
2080                }
2081            c = *eptr++;            c = *eptr++;
2082            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2083            }            }
# Line 1606  for (;;) Line 2099  for (;;)
2099            {            {
2100            for (fi = min;; fi++)            for (fi = min;; fi++)
2101              {              {
2102              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2103              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2104              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2105                if (eptr >= md->end_subject)
2106                  {
2107                  SCHECK_PARTIAL();
2108                  RRETURN(MATCH_NOMATCH);
2109                  }
2110              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2111              if (c > 255)              if (c > 255)
2112                {                {
# Line 1626  for (;;) Line 2124  for (;;)
2124            {            {
2125            for (fi = min;; fi++)            for (fi = min;; fi++)
2126              {              {
2127              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2128              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2129              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2130                if (eptr >= md->end_subject)
2131                  {
2132                  SCHECK_PARTIAL();
2133                  RRETURN(MATCH_NOMATCH);
2134                  }
2135              c = *eptr++;              c = *eptr++;
2136              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2137              }              }
# Line 1663  for (;;) Line 2166  for (;;)
2166              }              }
2167            for (;;)            for (;;)
2168              {              {
2169              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2170              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2171              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2172              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1682  for (;;) Line 2185  for (;;)
2185              }              }
2186            while (eptr >= pp)            while (eptr >= pp)
2187              {              {
2188              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
             eptr--;  
2189              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2190                eptr--;
2191              }              }
2192            }            }
2193    
# Line 1695  for (;;) Line 2198  for (;;)
2198    
2199    
2200      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2201      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
2202        mode, because Unicode properties are supported in non-UTF-8 mode. */
2203    
2204  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2205      case OP_XCLASS:      case OP_XCLASS:
# Line 1736  for (;;) Line 2240  for (;;)
2240    
2241        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2242          {          {
2243          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2244          GETCHARINC(c, eptr);            {
2245              SCHECK_PARTIAL();
2246              RRETURN(MATCH_NOMATCH);
2247              }
2248            GETCHARINCTEST(c, eptr);
2249          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2250          }          }
2251    
# Line 1753  for (;;) Line 2261  for (;;)
2261          {          {
2262          for (fi = min;; fi++)          for (fi = min;; fi++)
2263            {            {
2264            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2265            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2266            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2267            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2268                {
2269                SCHECK_PARTIAL();
2270                RRETURN(MATCH_NOMATCH);
2271                }
2272              GETCHARINCTEST(c, eptr);
2273            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2274            }            }
2275          /* Control never gets here */          /* Control never gets here */
# Line 1771  for (;;) Line 2284  for (;;)
2284            {            {
2285            int len = 1;            int len = 1;
2286            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2287            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2288            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2289            eptr += len;            eptr += len;
2290            }            }
2291          for(;;)          for(;;)
2292            {            {
2293            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2294            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2295            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2296            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2297            }            }
2298          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2299          }          }
# Line 1798  for (;;) Line 2311  for (;;)
2311        length = 1;        length = 1;
2312        ecode++;        ecode++;
2313        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2314        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2315            {
2316            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2317            RRETURN(MATCH_NOMATCH);
2318            }
2319        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2320        }        }
2321      else      else
# Line 1806  for (;;) Line 2323  for (;;)
2323    
2324      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2325        {        {
2326        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2327            {
2328            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2329            RRETURN(MATCH_NOMATCH);
2330            }
2331        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2332        ecode += 2;        ecode += 2;
2333        }        }
# Line 1822  for (;;) Line 2343  for (;;)
2343        ecode++;        ecode++;
2344        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2345    
2346        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2347            {
2348            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2349            RRETURN(MATCH_NOMATCH);
2350            }
2351    
2352        /* 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
2353        can use the fast lookup table. */        can use the fast lookup table. */
# Line 1836  for (;;) Line 2361  for (;;)
2361    
2362        else        else
2363          {          {
2364          int dc;          unsigned int dc;
2365          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2366          ecode += length;          ecode += length;
2367    
2368          /* If we have Unicode property support, we can use it to test the other          /* If we have Unicode property support, we can use it to test the other
2369          case of the character, if there is one. The result of _pcre_ucp_findchar() is          case of the character, if there is one. */
         < 0 if the char isn't found, and othercase is returned as zero if there  
         isn't one. */  
2370    
2371          if (fc != dc)          if (fc != dc)
2372            {            {
2373  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2374            int chartype;            if (dc != UCD_OTHERCASE(fc))
           int othercase;  
           if (_pcre_ucp_findchar(fc, &chartype, &othercase) < 0 || dc != othercase)  
2375  #endif  #endif
2376              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2377            }            }
# Line 1861  for (;;) Line 2382  for (;;)
2382    
2383      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2384        {        {
2385        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2386            {
2387            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2388            RRETURN(MATCH_NOMATCH);
2389            }
2390        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2391        ecode += 2;        ecode += 2;
2392        }        }
2393      break;      break;
2394    
2395      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2396    
2397      case OP_EXACT:      case OP_EXACT:
2398      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2399      ecode += 3;      ecode += 3;
2400      goto REPEATCHAR;      goto REPEATCHAR;
2401    
2402        case OP_POSUPTO:
2403        possessive = TRUE;
2404        /* Fall through */
2405    
2406      case OP_UPTO:      case OP_UPTO:
2407      case OP_MINUPTO:      case OP_MINUPTO:
2408      min = 0;      min = 0;
# Line 1882  for (;;) Line 2411  for (;;)
2411      ecode += 3;      ecode += 3;
2412      goto REPEATCHAR;      goto REPEATCHAR;
2413    
2414        case OP_POSSTAR:
2415        possessive = TRUE;
2416        min = 0;
2417        max = INT_MAX;
2418        ecode++;
2419        goto REPEATCHAR;
2420    
2421        case OP_POSPLUS:
2422        possessive = TRUE;
2423        min = 1;
2424        max = INT_MAX;
2425        ecode++;
2426        goto REPEATCHAR;
2427    
2428        case OP_POSQUERY:
2429        possessive = TRUE;
2430        min = 0;
2431        max = 1;
2432        ecode++;
2433        goto REPEATCHAR;
2434    
2435      case OP_STAR:      case OP_STAR:
2436      case OP_MINSTAR:      case OP_MINSTAR:
2437      case OP_PLUS:      case OP_PLUS:
# Line 1890  for (;;) Line 2440  for (;;)
2440      case OP_MINQUERY:      case OP_MINQUERY:
2441      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2442      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2443    
2444      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2445      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2446      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2447    
2448      /* 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. */  
2449    
2450      REPEATCHAR:      REPEATCHAR:
2451  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1905  for (;;) Line 2454  for (;;)
2454        length = 1;        length = 1;
2455        charptr = ecode;        charptr = ecode;
2456        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2457        ecode += length;        ecode += length;
2458    
2459        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 1913  for (;;) Line 2461  for (;;)
2461    
2462        if (length > 1)        if (length > 1)
2463          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2464  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2465          int othercase;          unsigned int othercase;
         int chartype;  
2466          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2467               _pcre_ucp_findchar(fc, &chartype, &othercase) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase > 0)  
2468            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2469            else oclength = 0;
2470  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2471    
2472          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2473            {            {
2474            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2475            /* Need braces because of following else */              memcmp(eptr, charptr, length) == 0) eptr += length;
2476            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2477              else if (oclength > 0 &&
2478                       eptr <= md->end_subject - oclength &&
2479                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2480    #endif  /* SUPPORT_UCP */
2481            else            else
2482              {              {
2483              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2484              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2485              }              }
2486            }            }
2487    
# Line 1943  for (;;) Line 2491  for (;;)
2491            {            {
2492            for (fi = min;; fi++)            for (fi = min;; fi++)
2493              {              {
2494              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2495              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2496              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2497              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2498              /* Need braces because of following else */                memcmp(eptr, charptr, length) == 0) eptr += length;
2499              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2500                else if (oclength > 0 &&
2501                         eptr <= md->end_subject - oclength &&
2502                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2503    #endif  /* SUPPORT_UCP */
2504              else              else
2505                {                {
2506                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2507                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2508                }                }
2509              }              }
2510            /* Control never gets here */            /* Control never gets here */
2511            }            }
2512          else  
2513            else  /* Maximize */
2514            {            {
2515            pp = eptr;            pp = eptr;
2516            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2517              {              {
2518              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2519              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2520              else if (oclength == 0) break;  #ifdef SUPPORT_UCP
2521              else              else if (oclength > 0 &&
2522                {                       eptr <= md->end_subject - oclength &&
2523                if (memcmp(eptr, occhars, oclength) != 0) break;                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2524                eptr += oclength;  #endif  /* SUPPORT_UCP */
2525                }              else break;
2526                }
2527    
2528              if (possessive) continue;
2529    
2530              for(;;)
2531                {
2532                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2533                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2534                if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2535    #ifdef SUPPORT_UCP
2536                eptr--;
2537                BACKCHAR(eptr);
2538    #else   /* without SUPPORT_UCP */
2539                eptr -= length;
2540    #endif  /* SUPPORT_UCP */
2541              }              }
           while (eptr >= pp)  
            {  
            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
            eptr -= length;  
            }  
           RRETURN(MATCH_NOMATCH);  
2542            }            }
2543          /* Control never gets here */          /* Control never gets here */
2544          }          }
# Line 1990  for (;;) Line 2551  for (;;)
2551  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2552    
2553      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
       {  
       if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
       fc = *ecode++;  
       }  
2554    
2555        fc = *ecode++;
2556    
2557      /* 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
2558      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
2559      caseful cases, for speed, since matching characters is likely to be quite      caseful cases, for speed, since matching characters is likely to be quite
# Line 2011  for (;;) Line 2570  for (;;)
2570        {        {
2571        fc = md->lcc[fc];        fc = md->lcc[fc];
2572        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2573            {
2574            if (eptr >= md->end_subject)
2575              {
2576              SCHECK_PARTIAL();
2577              RRETURN(MATCH_NOMATCH);
2578              }
2579          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2580            }
2581        if (min == max) continue;        if (min == max) continue;
2582        if (minimize)        if (minimize)
2583          {          {
2584          for (fi = min;; fi++)          for (fi = min;; fi++)
2585            {            {
2586            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2587            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2588            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2589                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2590                {
2591                SCHECK_PARTIAL();
2592              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2593                }
2594              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2595            }            }
2596          /* Control never gets here */          /* Control never gets here */
2597          }          }
2598        else        else  /* Maximize */
2599          {          {
2600          pp = eptr;          pp = eptr;
2601          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2033  for (;;) Line 2603  for (;;)
2603            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2604            eptr++;            eptr++;
2605            }            }
2606    
2607            if (possessive) continue;
2608    
2609          while (eptr >= pp)          while (eptr >= pp)
2610            {            {
2611            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2612            eptr--;            eptr--;
2613            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2614            }            }
# Line 2048  for (;;) Line 2621  for (;;)
2621    
2622      else      else
2623        {        {
2624        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2625            {
2626            if (eptr >= md->end_subject)
2627              {
2628              SCHECK_PARTIAL();
2629              RRETURN(MATCH_NOMATCH);
2630              }
2631            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2632            }
2633    
2634        if (min == max) continue;        if (min == max) continue;
2635    
2636        if (minimize)        if (minimize)
2637          {          {
2638          for (fi = min;; fi++)          for (fi = min;; fi++)
2639            {            {
2640            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2641            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2642            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2643              if (eptr >= md->end_subject)
2644                {
2645                SCHECK_PARTIAL();
2646              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2647                }
2648              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2649            }            }
2650          /* Control never gets here */          /* Control never gets here */
2651          }          }
2652        else        else  /* Maximize */
2653          {          {
2654          pp = eptr;          pp = eptr;
2655          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2069  for (;;) Line 2657  for (;;)
2657            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2658            eptr++;            eptr++;
2659            }            }
2660            if (possessive) continue;
2661    
2662          while (eptr >= pp)          while (eptr >= pp)
2663            {            {
2664            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2665            eptr--;            eptr--;
2666            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2667            }            }
# Line 2084  for (;;) Line 2674  for (;;)
2674      checking can be multibyte. */      checking can be multibyte. */
2675    
2676      case OP_NOT:      case OP_NOT:
2677      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2678          {
2679          SCHECK_PARTIAL();
2680          RRETURN(MATCH_NOMATCH);
2681          }
2682      ecode++;      ecode++;
2683      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2684      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2121  for (;;) Line 2715  for (;;)
2715      ecode += 3;      ecode += 3;
2716      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2717    
2718        case OP_NOTPOSSTAR:
2719        possessive = TRUE;
2720        min = 0;
2721        max = INT_MAX;
2722        ecode++;
2723        goto REPEATNOTCHAR;
2724    
2725        case OP_NOTPOSPLUS:
2726        possessive = TRUE;
2727        min = 1;
2728        max = INT_MAX;
2729        ecode++;
2730        goto REPEATNOTCHAR;
2731    
2732        case OP_NOTPOSQUERY:
2733        possessive = TRUE;
2734        min = 0;
2735        max = 1;
2736        ecode++;
2737        goto REPEATNOTCHAR;
2738    
2739        case OP_NOTPOSUPTO:
2740        possessive = TRUE;
2741        min = 0;
2742        max = GET2(ecode, 1);
2743        ecode += 3;
2744        goto REPEATNOTCHAR;
2745    
2746      case OP_NOTSTAR:      case OP_NOTSTAR:
2747      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2748      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2133  for (;;) Line 2755  for (;;)
2755      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2756      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2757    
2758      /* 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. */  
2759    
2760      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2761      fc = *ecode++;      fc = *ecode++;
2762    
2763      /* 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 2160  for (;;) Line 2779  for (;;)
2779        /* UTF-8 mode */        /* UTF-8 mode */
2780        if (utf8)        if (utf8)
2781          {          {
2782          register int d;          register unsigned int d;
2783          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2784            {            {
2785              if (eptr >= md->end_subject)
2786                {
2787                SCHECK_PARTIAL();
2788                RRETURN(MATCH_NOMATCH);
2789                }
2790            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2791            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2792            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2174  for (;;) Line 2798  for (;;)
2798        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2799          {          {
2800          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2801              {
2802              if (eptr >= md->end_subject)
2803                {
2804                SCHECK_PARTIAL();
2805                RRETURN(MATCH_NOMATCH);
2806                }
2807            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2808              }
2809          }          }
2810    
2811        if (min == max) continue;        if (min == max) continue;
# Line 2185  for (;;) Line 2816  for (;;)
2816          /* UTF-8 mode */          /* UTF-8 mode */
2817          if (utf8)          if (utf8)
2818            {            {
2819            register int d;            register unsigned int d;
2820            for (fi = min;; fi++)            for (fi = min;; fi++)
2821              {              {
2822              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2823              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2824                if (fi >= max) RRETURN(MATCH_NOMATCH);
2825                if (eptr >= md->end_subject)
2826                  {
2827                  SCHECK_PARTIAL();
2828                  RRETURN(MATCH_NOMATCH);
2829                  }
2830              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2831              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2832              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2833              }              }
2834            }            }
2835          else          else
# Line 2202  for (;;) Line 2838  for (;;)
2838            {            {
2839            for (fi = min;; fi++)            for (fi = min;; fi++)
2840              {              {
2841              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2842              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2843              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
2844                if (eptr >= md->end_subject)
2845                  {
2846                  SCHECK_PARTIAL();
2847                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2848                  }
2849                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2850              }              }
2851            }            }
2852          /* Control never gets here */          /* Control never gets here */
# Line 2221  for (;;) Line 2862  for (;;)
2862          /* UTF-8 mode */          /* UTF-8 mode */
2863          if (utf8)          if (utf8)
2864            {            {
2865            register int d;            register unsigned int d;
2866            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2867              {              {
2868              int len = 1;              int len = 1;
# Line 2231  for (;;) Line 2872  for (;;)
2872              if (fc == d) break;              if (fc == d) break;
2873              eptr += len;              eptr += len;
2874              }              }
2875            for(;;)          if (possessive) continue;
2876            for(;;)
2877              {              {
2878              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2879              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2880              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2881              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2248  for (;;) Line 2890  for (;;)
2890              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2891              eptr++;              eptr++;
2892              }              }
2893              if (possessive) continue;
2894            while (eptr >= pp)            while (eptr >= pp)
2895              {              {
2896              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2897              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2898              eptr--;              eptr--;
2899              }              }
# Line 2269  for (;;) Line 2912  for (;;)
2912        /* UTF-8 mode */        /* UTF-8 mode */
2913        if (utf8)        if (utf8)
2914          {          {
2915          register int d;          register unsigned int d;
2916          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2917            {            {
2918              if (eptr >= md->end_subject)
2919                {
2920                SCHECK_PARTIAL();
2921                RRETURN(MATCH_NOMATCH);
2922                }
2923            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2924            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
2925            }            }
# Line 2281  for (;;) Line 2929  for (;;)
2929        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2930          {          {
2931          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2932              {
2933              if (eptr >= md->end_subject)
2934                {
2935                SCHECK_PARTIAL();
2936                RRETURN(MATCH_NOMATCH);
2937                }
2938            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2939              }
2940          }          }
2941    
2942        if (min == max) continue;        if (min == max) continue;
# Line 2292  for (;;) Line 2947  for (;;)
2947          /* UTF-8 mode */          /* UTF-8 mode */
2948          if (utf8)          if (utf8)
2949            {            {
2950            register int d;            register unsigned int d;
2951            for (fi = min;; fi++)            for (fi = min;; fi++)
2952              {              {
2953              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2954              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2955              GETCHARINC(d, eptr);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2956              if (fi >= max || eptr >= md->end_subject || fc == d)              if (eptr >= md->end_subject)
2957                  {
2958                  SCHECK_PARTIAL();
2959                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2960                  }
2961                GETCHARINC(d, eptr);
2962                if (fc == d) RRETURN(MATCH_NOMATCH);
2963              }              }
2964            }            }
2965          else          else
# Line 2308  for (;;) Line 2968  for (;;)
2968            {            {
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, RM33);
2972              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2973              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
2974                if (eptr >= md->end_subject)
2975                  {
2976                  SCHECK_PARTIAL();
2977                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2978                  }
2979                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2980              }              }
2981            }            }
2982          /* Control never gets here */          /* Control never gets here */
# Line 2327  for (;;) Line 2992  for (;;)
2992          /* UTF-8 mode */          /* UTF-8 mode */
2993          if (utf8)          if (utf8)
2994            {            {
2995            register int d;            register unsigned int d;
2996            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2997              {              {
2998              int len = 1;              int len = 1;
# Line 2336  for (;;) Line 3001  for (;;)
3001              if (fc == d) break;              if (fc == d) break;
3002              eptr += len;              eptr += len;
3003              }              }
3004              if (possessive) continue;
3005            for(;;)            for(;;)
3006              {              {
3007              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3008              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3009              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3010              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2353  for (;;) Line 3019  for (;;)
3019              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
3020              eptr++;              eptr++;
3021              }              }
3022              if (possessive) continue;
3023            while (eptr >= pp)            while (eptr >= pp)
3024              {              {
3025              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3026              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3027              eptr--;              eptr--;
3028              }              }
# Line 2384  for (;;) Line 3051  for (;;)
3051      ecode += 3;      ecode += 3;
3052      goto REPEATTYPE;      goto REPEATTYPE;
3053    
3054        case OP_TYPEPOSSTAR:
3055        possessive = TRUE;
3056        min = 0;
3057        max = INT_MAX;
3058        ecode++;
3059        goto REPEATTYPE;
3060    
3061        case OP_TYPEPOSPLUS:
3062        possessive = TRUE;
3063        min = 1;
3064        max = INT_MAX;
3065        ecode++;
3066        goto REPEATTYPE;
3067    
3068        case OP_TYPEPOSQUERY:
3069        possessive = TRUE;
3070        min = 0;
3071        max = 1;
3072        ecode++;
3073        goto REPEATTYPE;
3074    
3075        case OP_TYPEPOSUPTO:
3076        possessive = TRUE;
3077        min = 0;
3078        max = GET2(ecode, 1);
3079        ecode += 3;
3080        goto REPEATTYPE;
3081    
3082      case OP_TYPESTAR:      case OP_TYPESTAR:
3083      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
3084      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2408  for (;;) Line 3103  for (;;)
3103        {        {
3104        prop_fail_result = ctype == OP_NOTPROP;        prop_fail_result = ctype == OP_NOTPROP;
3105        prop_type = *ecode++;        prop_type = *ecode++;
3106        if (prop_type >= 128)        prop_value = *ecode++;
         {  
         prop_test_against = prop_type - 128;  
         prop_test_variable = &prop_category;  
         }  
       else  
         {  
         prop_test_against = prop_type;  
         prop_test_variable = &prop_chartype;  
         }  
3107        }        }
3108      else prop_type = -1;      else prop_type = -1;
3109  #endif  #endif
3110    
3111      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3112      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
3113      (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  
3114      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
3115      and single-bytes. */      and single-bytes. */
3116    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3117      if (min > 0)      if (min > 0)
3118        {        {
3119  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3120        if (prop_type > 0)        if (prop_type >= 0)
3121          {          {
3122          for (i = 1; i <= min; i++)          switch(prop_type)
3123            {            {
3124            GETCHARINC(c, eptr);            case PT_ANY:
3125            prop_category = _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3126            if ((*prop_test_variable == prop_test_against) == prop_fail_result)            for (i = 1; i <= min; i++)
3127              RRETURN(MATCH_NOMATCH);              {
3128            }              if (eptr >= md->end_subject)
3129          }                {
3130                  SCHECK_PARTIAL();
3131                  RRETURN(MATCH_NOMATCH);
3132                  }
3133                GETCHARINCTEST(c, eptr);
3134                }
3135              break;
3136    
3137              case PT_LAMP:
3138              for (i = 1; i <= min; i++)
3139                {
3140                if (eptr >= md->end_subject)
3141                  {
3142                  SCHECK_PARTIAL();
3143                  RRETURN(MATCH_NOMATCH);
3144                  }
3145                GETCHARINCTEST(c, eptr);
3146                prop_chartype = UCD_CHARTYPE(c);
3147                if ((prop_chartype == ucp_Lu ||
3148                     prop_chartype == ucp_Ll ||
3149                     prop_chartype == ucp_Lt) == prop_fail_result)
3150                  RRETURN(MATCH_NOMATCH);
3151                }
3152              break;
3153    
3154              case PT_GC:
3155              for (i = 1; i <= min; i++)
3156                {
3157                if (eptr >= md->end_subject)
3158                  {
3159                  SCHECK_PARTIAL();
3160                  RRETURN(MATCH_NOMATCH);
3161                  }
3162                GETCHARINCTEST(c, eptr);
3163                prop_category = UCD_CATEGORY(c);
3164                if ((prop_category == prop_value) == prop_fail_result)
3165                  RRETURN(MATCH_NOMATCH);
3166                }
3167              break;
3168    
3169              case PT_PC:
3170              for (i = 1; i <= min; i++)
3171                {
3172                if (eptr >= md->end_subject)
3173                  {
3174                  SCHECK_PARTIAL();
3175                  RRETURN(MATCH_NOMATCH);
3176                  }
3177                GETCHARINCTEST(c, eptr);
3178                prop_chartype = UCD_CHARTYPE(c);
3179                if ((prop_chartype == prop_value) == prop_fail_result)
3180                  RRETURN(MATCH_NOMATCH);
3181                }
3182              break;
3183    
3184              case PT_SC:
3185              for (i = 1; i <= min; i++)
3186                {
3187                if (eptr >= md->end_subject)
3188                  {
3189                  SCHECK_PARTIAL();
3190                  RRETURN(MATCH_NOMATCH);
3191                  }
3192                GETCHARINCTEST(c, eptr);
3193                prop_script = UCD_SCRIPT(c);
3194                if ((prop_script == prop_value) == prop_fail_result)
3195                  RRETURN(MATCH_NOMATCH);
3196                }
3197              break;
3198    
3199              default:
3200              RRETURN(PCRE_ERROR_INTERNAL);
3201              }
3202            }
3203    
3204        /* Match extended Unicode sequences. We will get here only if the        /* Match extended Unicode sequences. We will get here only if the
3205        support is in the binary; otherwise a compile-time error occurs. */        support is in the binary; otherwise a compile-time error occurs. */
3206    
# Line 2452  for (;;) Line 3208  for (;;)
3208          {          {
3209          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3210            {            {
3211              if (eptr >= md->end_subject)
3212                {
3213                SCHECK_PARTIAL();
3214                RRETURN(MATCH_NOMATCH);
3215                }
3216            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3217            prop_category = _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase);            prop_category = UCD_CATEGORY(c);
3218            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3219            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3220              {              {
3221              int len = 1;              int len = 1;
3222              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3223                {                else { GETCHARLEN(c, eptr, len); }
3224                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase);  
3225              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3226              eptr += len;              eptr += len;
3227              }              }
# Line 2480  for (;;) Line 3239  for (;;)
3239          case OP_ANY:          case OP_ANY:
3240          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3241            {            {
3242            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3243               (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0))              {
3244                SCHECK_PARTIAL();
3245              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3246                }
3247              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3248              eptr++;
3249              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3250              }
3251            break;
3252    
3253            case OP_ALLANY:
3254            for (i = 1; i <= min; i++)
3255              {
3256              if (eptr >= md->end_subject)
3257                {
3258                SCHECK_PARTIAL();
3259                RRETURN(MATCH_NOMATCH);
3260                }
3261              eptr++;
3262            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3263            }            }
3264          break;          break;
3265    
3266          case OP_ANYBYTE:          case OP_ANYBYTE:
3267            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3268          eptr += min;          eptr += min;
3269          break;          break;
3270    
3271            case OP_ANYNL:
3272            for (i = 1; i <= min; i++)
3273              {
3274              if (eptr >= md->end_subject)
3275                {
3276                SCHECK_PARTIAL();
3277                RRETURN(MATCH_NOMATCH);
3278                }
3279              GETCHARINC(c, eptr);
3280              switch(c)
3281                {
3282                default: RRETURN(MATCH_NOMATCH);
3283                case 0x000d:
3284                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3285                break;
3286    
3287                case 0x000a:
3288                break;
3289    
3290                case 0x000b:
3291                case 0x000c:
3292                case 0x0085:
3293                case 0x2028:
3294                case 0x2029:
3295                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3296                break;
3297                }
3298              }
3299            break;
3300    
3301            case OP_NOT_HSPACE:
3302            for (i = 1; i <= min; i++)
3303              {
3304              if (eptr >= md->end_subject)
3305                {
3306                SCHECK_PARTIAL();
3307                RRETURN(MATCH_NOMATCH);
3308                }
3309              GETCHARINC(c, eptr);
3310              switch(c)
3311                {
3312                default: break;
3313                case 0x09:      /* HT */
3314                case 0x20:      /* SPACE */
3315                case 0xa0:      /* NBSP */
3316                case 0x1680:    /* OGHAM SPACE MARK */
3317                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3318                case 0x2000:    /* EN QUAD */
3319                case 0x2001:    /* EM QUAD */
3320                case 0x2002:    /* EN SPACE */
3321                case 0x2003:    /* EM SPACE */
3322                case 0x2004:    /* THREE-PER-EM SPACE */
3323                case 0x2005:    /* FOUR-PER-EM SPACE */
3324                case 0x2006:    /* SIX-PER-EM SPACE */
3325                case 0x2007:    /* FIGURE SPACE */
3326                case 0x2008:    /* PUNCTUATION SPACE */
3327                case 0x2009:    /* THIN SPACE */
3328                case 0x200A:    /* HAIR SPACE */
3329                case 0x202f:    /* NARROW NO-BREAK SPACE */
3330                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3331                case 0x3000:    /* IDEOGRAPHIC SPACE */
3332                RRETURN(MATCH_NOMATCH);
3333                }
3334              }
3335            break;
3336    
3337            case OP_HSPACE:
3338            for (i = 1; i <= min; i++)
3339              {
3340              if (eptr >= md->end_subject)
3341                {
3342                SCHECK_PARTIAL();
3343                RRETURN(MATCH_NOMATCH);
3344                }
3345              GETCHARINC(c, eptr);
3346              switch(c)
3347                {
3348                default: RRETURN(MATCH_NOMATCH);
3349                case 0x09:      /* HT */
3350                case 0x20:      /* SPACE */
3351                case 0xa0:      /* NBSP */
3352                case 0x1680:    /* OGHAM SPACE MARK */
3353                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3354                case 0x2000:    /* EN QUAD */
3355                case 0x2001:    /* EM QUAD */
3356                case 0x2002:    /* EN SPACE */
3357                case 0x2003:    /* EM SPACE */
3358                case 0x2004:    /* THREE-PER-EM SPACE */
3359                case 0x2005:    /* FOUR-PER-EM SPACE */
3360                case 0x2006:    /* SIX-PER-EM SPACE */
3361                case 0x2007:    /* FIGURE SPACE */
3362                case 0x2008:    /* PUNCTUATION SPACE */
3363                case 0x2009:    /* THIN SPACE */
3364                case 0x200A:    /* HAIR SPACE */
3365                case 0x202f:    /* NARROW NO-BREAK SPACE */
3366                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3367                case 0x3000:    /* IDEOGRAPHIC SPACE */
3368                break;
3369                }
3370              }
3371            break;
3372    
3373            case OP_NOT_VSPACE:
3374            for (i = 1; i <= min; i++)
3375              {
3376              if (eptr >= md->end_subject)
3377                {
3378                SCHECK_PARTIAL();
3379                RRETURN(MATCH_NOMATCH);
3380                }
3381              GETCHARINC(c, eptr);
3382              switch(c)
3383                {
3384                default: break;
3385                case 0x0a:      /* LF */
3386                case 0x0b:      /* VT */
3387                case 0x0c:      /* FF */
3388                case 0x0d:      /* CR */
3389                case 0x85:      /* NEL */
3390                case 0x2028:    /* LINE SEPARATOR */
3391                case 0x2029:    /* PARAGRAPH SEPARATOR */
3392                RRETURN(MATCH_NOMATCH);
3393                }
3394              }
3395            break;
3396    
3397            case OP_VSPACE:
3398            for (i = 1; i <= min; i++)
3399              {
3400              if (eptr >= md->end_subject)
3401                {
3402                SCHECK_PARTIAL();
3403                RRETURN(MATCH_NOMATCH);
3404                }
3405              GETCHARINC(c, eptr);
3406              switch(c)
3407                {
3408                default: RRETURN(MATCH_NOMATCH);
3409                case 0x0a:      /* LF */
3410                case 0x0b:      /* VT */
3411                case 0x0c:      /* FF */
3412                case 0x0d:      /* CR */
3413                case 0x85:      /* NEL */
3414                case 0x2028:    /* LINE SEPARATOR */
3415                case 0x2029:    /* PARAGRAPH SEPARATOR */
3416                break;
3417                }
3418              }
3419            break;
3420    
3421          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3422          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3423            {            {
3424            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3425                {
3426                SCHECK_PARTIAL();
3427                RRETURN(MATCH_NOMATCH);
3428                }
3429            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3430            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3431              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 2504  for (;;) Line 3435  for (;;)
3435          case OP_DIGIT:          case OP_DIGIT:
3436          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3437            {            {
3438            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3439               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3440                SCHECK_PARTIAL();
3441                RRETURN(MATCH_NOMATCH);
3442                }
3443              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3444              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3445            /* 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 */
3446            }            }
# Line 2514  for (;;) Line 3449  for (;;)
3449          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3450          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3451            {            {
3452            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3453               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3454                SCHECK_PARTIAL();
3455              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3456            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3457              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3458                RRETURN(MATCH_NOMATCH);
3459              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3460            }            }
3461          break;          break;
3462    
3463          case OP_WHITESPACE:          case OP_WHITESPACE:
3464          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3465            {            {
3466            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3467               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3468                SCHECK_PARTIAL();
3469                RRETURN(MATCH_NOMATCH);
3470                }
3471              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3472              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3473            /* 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 */
3474            }            }
# Line 2535  for (;;) Line 3478  for (;;)
3478          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3479            {            {
3480            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3481               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3482              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3483            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3484            }            }
3485          break;          break;
3486    
3487          case OP_WORDCHAR:          case OP_WORDCHAR:
3488          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3489            {            {
3490            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3491               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3492                SCHECK_PARTIAL();
3493                RRETURN(MATCH_NOMATCH);
3494                }
3495              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3496              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3497            /* 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 */
3498            }            }
# Line 2564  for (;;) Line 3511  for (;;)
3511        switch(ctype)        switch(ctype)
3512          {          {
3513          case OP_ANY:          case OP_ANY:
3514          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3515            {            {
3516            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3517              if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH);              {
3518                SCHECK_PARTIAL();
3519                RRETURN(MATCH_NOMATCH);
3520                }
3521              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3522              eptr++;
3523            }            }
3524          else eptr += min;          break;
3525    
3526            case OP_ALLANY:
3527            if (eptr > md->end_subject - min)
3528              {
3529              SCHECK_PARTIAL();
3530              RRETURN(MATCH_NOMATCH);
3531              }
3532            eptr += min;
3533          break;          break;
3534    
3535          case OP_ANYBYTE:          case OP_ANYBYTE:
3536            if (eptr > md->end_subject - min)
3537              {
3538              SCHECK_PARTIAL();
3539              RRETURN(MATCH_NOMATCH);
3540              }
3541          eptr += min;          eptr += min;
3542          break;          break;
3543    
3544            case OP_ANYNL:
3545            for (i = 1; i <= min; i++)
3546              {
3547              if (eptr >= md->end_subject)
3548                {
3549                SCHECK_PARTIAL();
3550                RRETURN(MATCH_NOMATCH);
3551                }
3552              switch(*eptr++)
3553                {
3554                default: RRETURN(MATCH_NOMATCH);
3555                case 0x000d:
3556                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3557                break;
3558                case 0x000a:
3559                break;
3560    
3561                case 0x000b:
3562                case 0x000c:
3563                case 0x0085:
3564                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3565                break;
3566                }
3567              }
3568            break;
3569    
3570            case OP_NOT_HSPACE:
3571            for (i = 1; i <= min; i++)
3572              {
3573              if (eptr >= md->end_subject)
3574                {
3575                SCHECK_PARTIAL();
3576                RRETURN(MATCH_NOMATCH);
3577                }
3578              switch(*eptr++)
3579                {
3580                default: break;
3581                case 0x09:      /* HT */
3582                case 0x20:      /* SPACE */
3583                case 0xa0:      /* NBSP */
3584                RRETURN(MATCH_NOMATCH);
3585                }
3586              }
3587            break;
3588    
3589            case OP_HSPACE:
3590            for (i = 1; i <= min; i++)
3591              {
3592              if (eptr >= md->end_subject)
3593                {
3594                SCHECK_PARTIAL();
3595                RRETURN(MATCH_NOMATCH);
3596                }
3597              switch(*eptr++)
3598                {
3599                default: RRETURN(MATCH_NOMATCH);
3600                case 0x09:      /* HT */
3601                case 0x20:      /* SPACE */
3602                case 0xa0:      /* NBSP */
3603                break;
3604                }
3605              }
3606            break;
3607    
3608            case OP_NOT_VSPACE:
3609            for (i = 1; i <= min; i++)
3610              {
3611              if (eptr >= md->end_subject)
3612                {
3613                SCHECK_PARTIAL();
3614                RRETURN(MATCH_NOMATCH);
3615                }
3616              switch(*eptr++)
3617                {
3618                default: break;
3619                case 0x0a:      /* LF */
3620                case 0x0b:      /* VT */
3621                case 0x0c:      /* FF */
3622                case 0x0d:      /* CR */
3623                case 0x85:      /* NEL */
3624                RRETURN(MATCH_NOMATCH);
3625                }
3626              }
3627            break;
3628    
3629            case OP_VSPACE:
3630            for (i = 1; i <= min; i++)
3631              {
3632              if (eptr >= md->end_subject)
3633                {
3634                SCHECK_PARTIAL();
3635                RRETURN(MATCH_NOMATCH);
3636                }
3637              switch(*eptr++)
3638                {
3639                default: RRETURN(MATCH_NOMATCH);
3640                case 0x0a:      /* LF */
3641                case 0x0b:      /* VT */
3642                case 0x0c:      /* FF */
3643                case 0x0d:      /* CR */
3644                case 0x85:      /* NEL */
3645                break;
3646                }
3647              }
3648            break;
3649    
3650          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3651          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3652              {
3653              if (eptr >= md->end_subject)
3654                {
3655                SCHECK_PARTIAL();
3656                RRETURN(MATCH_NOMATCH);
3657                }
3658            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3659              }
3660          break;          break;
3661    
3662          case OP_DIGIT:          case OP_DIGIT:
3663          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3664              {
3665              if (eptr >= md->end_subject)
3666                {
3667                SCHECK_PARTIAL();
3668                RRETURN(MATCH_NOMATCH);
3669                }
3670            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3671              }
3672          break;          break;
3673    
3674          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3675          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3676              {
3677              if (eptr >= md->end_subject)
3678                {
3679                SCHECK_PARTIAL();
3680                RRETURN(MATCH_NOMATCH);
3681                }
3682            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3683              }
3684          break;          break;
3685    
3686          case OP_WHITESPACE:          case OP_WHITESPACE:
3687          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3688              {
3689              if (eptr >= md->end_subject)
3690                {
3691                SCHECK_PARTIAL();
3692                RRETURN(MATCH_NOMATCH);
3693                }
3694            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3695              }
3696          break;          break;
3697    
3698          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3699          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3700              {
3701              if (eptr >= md->end_subject)
3702                {
3703                SCHECK_PARTIAL();
3704                RRETURN(MATCH_NOMATCH);
3705                }
3706            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3707              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3708              }
3709          break;          break;
3710    
3711          case OP_WORDCHAR:          case OP_WORDCHAR:
3712          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3713              {
3714              if (eptr >= md->end_subject)
3715                {
3716                SCHECK_PARTIAL();
3717                RRETURN(MATCH_NOMATCH);
3718                }
3719            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3720              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3721              }
3722          break;          break;
3723    
3724          default:          default:
# Line 2624  for (;;) Line 3737  for (;;)
3737      if (minimize)      if (minimize)
3738        {        {
3739  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3740        if (prop_type > 0)        if (prop_type >= 0)
3741          {          {
3742          for (fi = min;; fi++)          switch(prop_type)
3743            {            {
3744            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            case PT_ANY:
3745            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            for (fi = min;; fi++)
3746            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              {
3747            GETCHARINC(c, eptr);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3748            prop_category = _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3749            if ((*prop_test_variable == prop_test_against) == prop_fail_result)              if (fi >= max) RRETURN(MATCH_NOMATCH);
3750              RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3751                  {
3752                  SCHECK_PARTIAL();
3753                  RRETURN(MATCH_NOMATCH);
3754                  }
3755                GETCHARINC(c, eptr);
3756                if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3757                }
3758              /* Control never gets here */
3759    
3760              case PT_LAMP:
3761              for (fi = min;; fi++)
3762                {
3763                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3764                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3765                if (fi >= max) RRETURN(MATCH_NOMATCH);
3766                if (eptr >= md->end_subject)
3767                  {
3768                  SCHECK_PARTIAL();
3769                  RRETURN(MATCH_NOMATCH);
3770                  }
3771                GETCHARINC(c, eptr);
3772                prop_chartype = UCD_CHARTYPE(c);
3773                if ((prop_chartype == ucp_Lu ||
3774                     prop_chartype == ucp_Ll ||
3775                     prop_chartype == ucp_Lt) == prop_fail_result)
3776                  RRETURN(MATCH_NOMATCH);
3777                }
3778              /* Control never gets here */
3779    
3780              case PT_GC:
3781              for (fi = min;; fi++)
3782                {
3783                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3784                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3785                if (fi >= max) RRETURN(MATCH_NOMATCH);
3786                if (eptr >= md->end_subject)
3787                  {
3788                  SCHECK_PARTIAL();
3789                  RRETURN(MATCH_NOMATCH);
3790                  }
3791                GETCHARINC(c, eptr);
3792                prop_category = UCD_CATEGORY(c);
3793                if ((prop_category == prop_value) == prop_fail_result)
3794                  RRETURN(MATCH_NOMATCH);
3795                }
3796              /* Control never gets here */
3797    
3798              case PT_PC:
3799              for (fi = min;; fi++)
3800                {
3801                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3802                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3803                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);
3810                prop_chartype = UCD_CHARTYPE(c);
3811                if ((prop_chartype == prop_value) == prop_fail_result)
3812                  RRETURN(MATCH_NOMATCH);
3813                }
3814              /* Control never gets here */
3815    
3816              case PT_SC:
3817              for (fi = min;; fi++)
3818                {
3819                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3820                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3821                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);
3828                prop_script = UCD_SCRIPT(c);
3829                if ((prop_script == prop_value) == prop_fail_result)
3830                  RRETURN(MATCH_NOMATCH);
3831                }
3832              /* Control never gets here */
3833    
3834              default:
3835              RRETURN(PCRE_ERROR_INTERNAL);
3836            }            }
3837          }          }
3838    
# Line 2645  for (;;) Line 3843  for (;;)
3843          {          {
3844          for (fi = min;; fi++)          for (fi = min;; fi++)
3845            {            {
3846            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3847            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3848            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3849              if (eptr >= md->end_subject)
3850                {
3851                SCHECK_PARTIAL();
3852                RRETURN(MATCH_NOMATCH);
3853                }
3854            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3855            prop_category = _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase);            prop_category = UCD_CATEGORY(c);
3856            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3857            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3858              {              {
3859              int len = 1;              int len = 1;
3860              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3861                {                else { GETCHARLEN(c, eptr, len); }
3862                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase);  
3863              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3864              eptr += len;              eptr += len;
3865              }              }
# Line 2674  for (;;) Line 3875  for (;;)
3875          {          {
3876          for (fi = min;; fi++)          for (fi = min;; fi++)
3877            {            {
3878            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3879            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3880            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3881              if (eptr >= md->end_subject)
3882                {
3883                SCHECK_PARTIAL();
3884                RRETURN(MATCH_NOMATCH);
3885                }
3886              if (ctype == OP_ANY && IS_NEWLINE(eptr))
3887                RRETURN(MATCH_NOMATCH);
3888            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3889            switch(ctype)            switch(ctype)
3890              {              {
3891              case OP_ANY:              case OP_ANY:        /* This is the non-NL case */
3892              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3893                case OP_ANYBYTE:
3894              break;              break;
3895    
3896              case OP_ANYBYTE:              case OP_ANYNL:
3897                switch(c)
3898                  {
3899                  default: RRETURN(MATCH_NOMATCH);
3900                  case 0x000d:
3901                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3902                  break;
3903                  case 0x000a:
3904                  break;
3905    
3906                  case 0x000b:
3907                  case 0x000c:
3908                  case 0x0085:
3909                  case 0x2028:
3910                  case 0x2029:
3911                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3912                  break;
3913                  }
3914                break;
3915    
3916                case OP_NOT_HSPACE:
3917                switch(c)
3918                  {
3919                  default: break;
3920                  case 0x09:      /* HT */
3921                  case 0x20:      /* SPACE */
3922                  case 0xa0:      /* NBSP */
3923                  case 0x1680:    /* OGHAM SPACE MARK */
3924                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3925                  case 0x2000:    /* EN QUAD */
3926                  case 0x2001:    /* EM QUAD */
3927                  case 0x2002:    /* EN SPACE */
3928                  case 0x2003:    /* EM SPACE */
3929                  case 0x2004:    /* THREE-PER-EM SPACE */
3930                  case 0x2005:    /* FOUR-PER-EM SPACE */
3931                  case 0x2006:    /* SIX-PER-EM SPACE */
3932                  case 0x2007:    /* FIGURE SPACE */
3933                  case 0x2008:    /* PUNCTUATION SPACE */
3934                  case 0x2009:    /* THIN SPACE */
3935                  case 0x200A:    /* HAIR SPACE */
3936                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3937                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3938                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3939                  RRETURN(MATCH_NOMATCH);
3940                  }
3941                break;
3942    
3943                case OP_HSPACE:
3944                switch(c)
3945                  {
3946                  default: RRETURN(MATCH_NOMATCH);
3947                  case 0x09:      /* HT */
3948                  case 0x20:      /* SPACE */
3949                  case 0xa0:      /* NBSP */
3950                  case 0x1680:    /* OGHAM SPACE MARK */
3951                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3952                  case 0x2000:    /* EN QUAD */
3953                  case 0x2001:    /* EM QUAD */
3954                  case 0x2002:    /* EN SPACE */
3955                  case 0x2003:    /* EM SPACE */
3956                  case 0x2004:    /* THREE-PER-EM SPACE */
3957                  case 0x2005:    /* FOUR-PER-EM SPACE */
3958                  case 0x2006:    /* SIX-PER-EM SPACE */
3959                  case 0x2007:    /* FIGURE SPACE */
3960                  case 0x2008:    /* PUNCTUATION SPACE */
3961                  case 0x2009:    /* THIN SPACE */
3962                  case 0x200A:    /* HAIR SPACE */
3963                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3964                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3965                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3966                  break;
3967                  }
3968                break;
3969    
3970                case OP_NOT_VSPACE:
3971                switch(c)
3972                  {
3973                  default: break;
3974                  case 0x0a:      /* LF */
3975                  case 0x0b:      /* VT */
3976                  case 0x0c:      /* FF */
3977                  case 0x0d:      /* CR */
3978                  case 0x85:      /* NEL */
3979                  case 0x2028:    /* LINE SEPARATOR */
3980                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3981                  RRETURN(MATCH_NOMATCH);
3982                  }
3983                break;
3984    
3985                case OP_VSPACE:
3986                switch(c)
3987                  {
3988                  default: RRETURN(MATCH_NOMATCH);
3989                  case 0x0a:      /* LF */
3990                  case 0x0b:      /* VT */
3991                  case 0x0c:      /* FF */
3992                  case 0x0d:      /* CR */
3993                  case 0x85:      /* NEL */
3994                  case 0x2028:    /* LINE SEPARATOR */
3995                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3996                  break;
3997                  }
3998              break;              break;
3999    
4000              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2729  for (;;) Line 4038  for (;;)
4038          {          {
4039          for (fi = min;; fi++)          for (fi = min;; fi++)
4040            {            {
4041            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4042            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4043            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
4044              if (eptr >= md->end_subject)
4045                {
4046                SCHECK_PARTIAL();
4047                RRETURN(MATCH_NOMATCH);
4048                }
4049              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4050                RRETURN(MATCH_NOMATCH);
4051            c = *eptr++;            c = *eptr++;
4052            switch(ctype)            switch(ctype)
4053              {              {
4054              case OP_ANY:              case OP_ANY:     /* This is the non-NL case */
4055              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
4056                case OP_ANYBYTE:
4057              break;              break;
4058    
4059              case OP_ANYBYTE:              case OP_ANYNL:
4060                switch(c)
4061                  {
4062                  default: RRETURN(MATCH_NOMATCH);
4063                  case 0x000d:
4064                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4065                  break;
4066    
4067                  case 0x000a:
4068                  break;
4069    
4070                  case 0x000b:
4071                  case 0x000c:
4072                  case 0x0085:
4073                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4074                  break;
4075                  }
4076                break;
4077    
4078                case OP_NOT_HSPACE:
4079                switch(c)
4080                  {
4081                  default: break;
4082                  case 0x09:      /* HT */
4083                  case 0x20:      /* SPACE */
4084                  case 0xa0:      /* NBSP */
4085                  RRETURN(MATCH_NOMATCH);
4086                  }
4087                break;
4088    
4089                case OP_HSPACE:
4090                switch(c)
4091                  {
4092                  default: RRETURN(MATCH_NOMATCH);
4093                  case 0x09:      /* HT */
4094                  case 0x20:      /* SPACE */
4095                  case 0xa0:      /* NBSP */
4096                  break;
4097                  }
4098                break;
4099    
4100                case OP_NOT_VSPACE:
4101                switch(c)
4102                  {
4103                  default: break;
4104                  case 0x0a:      /* LF */
4105                  case 0x0b:      /* VT */
4106                  case 0x0c:      /* FF */
4107                  case 0x0d:      /* CR */
4108                  case 0x85:      /* NEL */
4109                  RRETURN(MATCH_NOMATCH);
4110                  }
4111                break;
4112    
4113                case OP_VSPACE:
4114                switch(c)
4115                  {
4116                  default: RRETURN(MATCH_NOMATCH);
4117                  case 0x0a:      /* LF */
4118                  case 0x0b:      /* VT */
4119                  case 0x0c:      /* FF */
4120                  case 0x0d:      /* CR */
4121                  case 0x85:      /* NEL */
4122                  break;
4123                  }
4124              break;              break;
4125    
4126              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2774  for (;;) Line 4155  for (;;)
4155        /* Control never gets here */        /* Control never gets here */
4156        }        }
4157    
4158      /* If maximizing it is worth using inline code for speed, doing the type      /* If maximizing, it is worth using inline code for speed, doing the type
4159      test once at the start (i.e. keep it out of the loop). Again, keep the      test once at the start (i.e. keep it out of the loop). Again, keep the
4160      UTF-8 and UCP stuff separate. */      UTF-8 and UCP stuff separate. */
4161    
# Line 2782  for (;;) Line 4163  for (;;)
4163        {        {
4164        pp = eptr;  /* Remember where we started */        pp = eptr;  /* Remember where we started */
4165    
4166  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4167        if (prop_type > 0)        if (prop_type >= 0)
4168          {          {
4169          for (i = min; i < max; i++)          switch(prop_type)
4170            {            {
4171            int len = 1;            case PT_ANY:
4172            if (eptr >= md->end_subject) break;            for (i = min; i < max; i++)
4173            GETCHARLEN(c, eptr, len);              {
4174            prop_category = _pcre_ucp_findchar(c, &prop_chartype, &prop_othercase);              int len = 1;
4175            if ((*prop_test_variable == prop_test_against) == prop_fail_result)              if (eptr >= md->end_subject) break;
4176              break;              GETCHARLEN(c, eptr, len);
4177            eptr+= len;              if (prop_fail_result) break;
4178                eptr+= len;
4179                }
4180              break;
4181