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

Diff of /code/trunk/pcre_study.c

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

revision 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 657 by ph10, Mon Aug 15 17:39:09 2011 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2006 University of Cambridge             Copyright (c) 1997-2010 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  supporting functions. */  supporting functions. */
43    
44    
45    #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49  #include "pcre_internal.h"  #include "pcre_internal.h"
50    
51    #define SET_BIT(c) start_bits[c/8] |= (1 << (c&7))
52    
53    /* Returns from set_start_bits() */
54    
55    enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE, SSB_UNKNOWN };
56    
57    
58    
59    /*************************************************
60    *   Find the minimum subject length for a group  *
61    *************************************************/
62    
63    /* Scan a parenthesized group and compute the minimum length of subject that
64    is needed to match it. This is a lower bound; it does not mean there is a
65    string of that length that matches. In UTF8 mode, the result is in characters
66    rather than bytes.
67    
68    Arguments:
69      code        pointer to start of group (the bracket)
70      startcode   pointer to start of the whole pattern
71      options     the compiling options
72      had_accept  pointer to flag for (*ACCEPT) encountered
73      int         RECURSE depth
74    
75    Returns:   the minimum length
76               -1 if \C was encountered
77               -2 internal error (missing capturing bracket)
78               -3 internal error (opcode not listed)
79    */
80    
81    static int
82    find_minlength(const uschar *code, const uschar *startcode, int options,
83      BOOL *had_accept_ptr, int recurse_depth)
84    {
85    int length = -1;
86    BOOL utf8 = (options & PCRE_UTF8) != 0;
87    BOOL had_recurse = FALSE;
88    register int branchlength = 0;
89    register uschar *cc = (uschar *)code + 1 + LINK_SIZE;
90    
91    if (*code == OP_CBRA || *code == OP_SCBRA ||
92        *code == OP_CBRAPOS || *code == OP_SCBRAPOS) cc += 2;
93    
94    /* Scan along the opcodes for this branch. If we get to the end of the
95    branch, check the length against that of the other branches. */
96    
97    for (;;)
98      {
99      int d, min;
100      uschar *cs, *ce;
101      register int op = *cc;
102    
103      switch (op)
104        {
105        case OP_COND:
106        case OP_SCOND:
107    
108        /* If there is only one branch in a condition, the implied branch has zero
109        length, so we don't add anything. This covers the DEFINE "condition"
110        automatically. */
111    
112        cs = cc + GET(cc, 1);
113        if (*cs != OP_ALT)
114          {
115          cc = cs + 1 + LINK_SIZE;
116          break;
117          }
118    
119        /* Otherwise we can fall through and treat it the same as any other
120        subpattern. */
121    
122        case OP_CBRA:
123        case OP_SCBRA:
124        case OP_BRA:
125        case OP_SBRA:
126        case OP_CBRAPOS:
127        case OP_SCBRAPOS:
128        case OP_BRAPOS:
129        case OP_SBRAPOS:
130        case OP_ONCE:
131        d = find_minlength(cc, startcode, options, had_accept_ptr, recurse_depth);
132        if (d < 0) return d;
133        branchlength += d;
134        if (*had_accept_ptr) return branchlength;
135        do cc += GET(cc, 1); while (*cc == OP_ALT);
136        cc += 1 + LINK_SIZE;
137        break;
138    
139        /* Reached end of a branch; if it's a ket it is the end of a nested
140        call. If it's ALT it is an alternation in a nested call. If it is END it's
141        the end of the outer call. All can be handled by the same code. If it is
142        ACCEPT, it is essentially the same as END, but we set a flag so that
143        counting stops. */
144    
145        case OP_ACCEPT:
146        case OP_ASSERT_ACCEPT:
147        *had_accept_ptr = TRUE;
148        /* Fall through */
149        case OP_ALT:
150        case OP_KET:
151        case OP_KETRMAX:
152        case OP_KETRMIN:
153        case OP_KETRPOS:
154        case OP_END:
155        if (length < 0 || (!had_recurse && branchlength < length))
156          length = branchlength;
157        if (op != OP_ALT) return length;
158        cc += 1 + LINK_SIZE;
159        branchlength = 0;
160        had_recurse = FALSE;
161        break;
162    
163        /* Skip over assertive subpatterns */
164    
165        case OP_ASSERT:
166        case OP_ASSERT_NOT:
167        case OP_ASSERTBACK:
168        case OP_ASSERTBACK_NOT:
169        do cc += GET(cc, 1); while (*cc == OP_ALT);
170        /* Fall through */
171    
172        /* Skip over things that don't match chars */
173    
174        case OP_REVERSE:
175        case OP_CREF:
176        case OP_NCREF:
177        case OP_RREF:
178        case OP_NRREF:
179        case OP_DEF:
180        case OP_CALLOUT:
181        case OP_SOD:
182        case OP_SOM:
183        case OP_EOD:
184        case OP_EODN:
185        case OP_CIRC:
186        case OP_CIRCM:
187        case OP_DOLL:
188        case OP_DOLLM:
189        case OP_NOT_WORD_BOUNDARY:
190        case OP_WORD_BOUNDARY:
191        cc += _pcre_OP_lengths[*cc];
192        break;
193    
194        /* Skip over a subpattern that has a {0} or {0,x} quantifier */
195    
196        case OP_BRAZERO:
197        case OP_BRAMINZERO:
198        case OP_BRAPOSZERO:
199        case OP_SKIPZERO:
200        cc += _pcre_OP_lengths[*cc];
201        do cc += GET(cc, 1); while (*cc == OP_ALT);
202        cc += 1 + LINK_SIZE;
203        break;
204    
205        /* Handle literal characters and + repetitions */
206    
207        case OP_CHAR:
208        case OP_CHARI:
209        case OP_NOT:
210        case OP_NOTI:
211        case OP_PLUS:
212        case OP_PLUSI:
213        case OP_MINPLUS:
214        case OP_MINPLUSI:
215        case OP_POSPLUS:
216        case OP_POSPLUSI:
217        case OP_NOTPLUS:
218        case OP_NOTPLUSI:
219        case OP_NOTMINPLUS:
220        case OP_NOTMINPLUSI:
221        case OP_NOTPOSPLUS:
222        case OP_NOTPOSPLUSI:
223        branchlength++;
224        cc += 2;
225    #ifdef SUPPORT_UTF8
226        if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];
227    #endif
228        break;
229    
230        case OP_TYPEPLUS:
231        case OP_TYPEMINPLUS:
232        case OP_TYPEPOSPLUS:
233        branchlength++;
234        cc += (cc[1] == OP_PROP || cc[1] == OP_NOTPROP)? 4 : 2;
235        break;
236    
237        /* Handle exact repetitions. The count is already in characters, but we
238        need to skip over a multibyte character in UTF8 mode.  */
239    
240        case OP_EXACT:
241        case OP_EXACTI:
242        case OP_NOTEXACT:
243        case OP_NOTEXACTI:
244        branchlength += GET2(cc,1);
245        cc += 4;
246    #ifdef SUPPORT_UTF8
247        if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];
248    #endif
249        break;
250    
251        case OP_TYPEEXACT:
252        branchlength += GET2(cc,1);
253        cc += (cc[3] == OP_PROP || cc[3] == OP_NOTPROP)? 6 : 4;
254        break;
255    
256        /* Handle single-char non-literal matchers */
257    
258        case OP_PROP:
259        case OP_NOTPROP:
260        cc += 2;
261        /* Fall through */
262    
263        case OP_NOT_DIGIT:
264        case OP_DIGIT:
265        case OP_NOT_WHITESPACE:
266        case OP_WHITESPACE:
267        case OP_NOT_WORDCHAR:
268        case OP_WORDCHAR:
269        case OP_ANY:
270        case OP_ALLANY:
271        case OP_EXTUNI:
272        case OP_HSPACE:
273        case OP_NOT_HSPACE:
274        case OP_VSPACE:
275        case OP_NOT_VSPACE:
276        branchlength++;
277        cc++;
278        break;
279    
280        /* "Any newline" might match two characters, but it also might match just
281        one. */
282    
283        case OP_ANYNL:
284        branchlength += 1;
285        cc++;
286        break;
287    
288        /* The single-byte matcher means we can't proceed in UTF-8 mode */
289    
290        case OP_ANYBYTE:
291    #ifdef SUPPORT_UTF8
292        if (utf8) return -1;
293    #endif
294        branchlength++;
295        cc++;
296        break;
297    
298        /* For repeated character types, we have to test for \p and \P, which have
299        an extra two bytes of parameters. */
300    
301        case OP_TYPESTAR:
302        case OP_TYPEMINSTAR:
303        case OP_TYPEQUERY:
304        case OP_TYPEMINQUERY:
305        case OP_TYPEPOSSTAR:
306        case OP_TYPEPOSQUERY:
307        if (cc[1] == OP_PROP || cc[1] == OP_NOTPROP) cc += 2;
308        cc += _pcre_OP_lengths[op];
309        break;
310    
311        case OP_TYPEUPTO:
312        case OP_TYPEMINUPTO:
313        case OP_TYPEPOSUPTO:
314        if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2;
315        cc += _pcre_OP_lengths[op];
316        break;
317    
318        /* Check a class for variable quantification */
319    
320    #ifdef SUPPORT_UTF8
321        case OP_XCLASS:
322        cc += GET(cc, 1) - 33;
323        /* Fall through */
324    #endif
325    
326        case OP_CLASS:
327        case OP_NCLASS:
328        cc += 33;
329    
330        switch (*cc)
331          {
332          case OP_CRPLUS:
333          case OP_CRMINPLUS:
334          branchlength++;
335          /* Fall through */
336    
337          case OP_CRSTAR:
338          case OP_CRMINSTAR:
339          case OP_CRQUERY:
340          case OP_CRMINQUERY:
341          cc++;
342          break;
343    
344          case OP_CRRANGE:
345          case OP_CRMINRANGE:
346          branchlength += GET2(cc,1);
347          cc += 5;
348          break;
349    
350          default:
351          branchlength++;
352          break;
353          }
354        break;
355    
356        /* Backreferences and subroutine calls are treated in the same way: we find
357        the minimum length for the subpattern. A recursion, however, causes an
358        a flag to be set that causes the length of this branch to be ignored. The
359        logic is that a recursion can only make sense if there is another
360        alternation that stops the recursing. That will provide the minimum length
361        (when no recursion happens). A backreference within the group that it is
362        referencing behaves in the same way.
363    
364        If PCRE_JAVASCRIPT_COMPAT is set, a backreference to an unset bracket
365        matches an empty string (by default it causes a matching failure), so in
366        that case we must set the minimum length to zero. */
367    
368        case OP_REF:
369        case OP_REFI:
370        if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)
371          {
372          ce = cs = (uschar *)_pcre_find_bracket(startcode, utf8, GET2(cc, 1));
373          if (cs == NULL) return -2;
374          do ce += GET(ce, 1); while (*ce == OP_ALT);
375          if (cc > cs && cc < ce)
376            {
377            d = 0;
378            had_recurse = TRUE;
379            }
380          else
381            {
382            d = find_minlength(cs, startcode, options, had_accept_ptr,
383              recurse_depth);
384            *had_accept_ptr = FALSE;
385            }
386          }
387        else d = 0;
388        cc += 3;
389    
390        /* Handle repeated back references */
391    
392        switch (*cc)
393          {
394          case OP_CRSTAR:
395          case OP_CRMINSTAR:
396          case OP_CRQUERY:
397          case OP_CRMINQUERY:
398          min = 0;
399          cc++;
400          break;
401    
402          case OP_CRPLUS:
403          case OP_CRMINPLUS:
404          min = 1;
405          cc++;
406          break;
407    
408          case OP_CRRANGE:
409          case OP_CRMINRANGE:
410          min = GET2(cc, 1);
411          cc += 5;
412          break;
413    
414          default:
415          min = 1;
416          break;
417          }
418    
419        branchlength += min * d;
420        break;
421    
422        /* We can easily detect direct recursion, but not mutual recursion. This is
423        caught by a recursion depth count. */
424    
425        case OP_RECURSE:
426        cs = ce = (uschar *)startcode + GET(cc, 1);
427        if (cs == NULL) return -2;
428        do ce += GET(ce, 1); while (*ce == OP_ALT);
429        if ((cc > cs && cc < ce) || recurse_depth > 10)
430          had_recurse = TRUE;
431        else
432          {
433          branchlength += find_minlength(cs, startcode, options, had_accept_ptr,
434            recurse_depth + 1);
435          *had_accept_ptr = FALSE;
436          }
437        cc += 1 + LINK_SIZE;
438        break;
439    
440        /* Anything else does not or need not match a character. We can get the
441        item's length from the table, but for those that can match zero occurrences
442        of a character, we must take special action for UTF-8 characters. As it
443        happens, the "NOT" versions of these opcodes are used at present only for
444        ASCII characters, so they could be omitted from this list. However, in
445        future that may change, so we include them here so as not to leave a
446        gotcha for a future maintainer. */
447    
448        case OP_UPTO:
449        case OP_UPTOI:
450        case OP_NOTUPTO:
451        case OP_NOTUPTOI:
452        case OP_MINUPTO:
453        case OP_MINUPTOI:
454        case OP_NOTMINUPTO:
455        case OP_NOTMINUPTOI:
456        case OP_POSUPTO:
457        case OP_POSUPTOI:
458        case OP_NOTPOSUPTO:
459        case OP_NOTPOSUPTOI:
460    
461        case OP_STAR:
462        case OP_STARI:
463        case OP_NOTSTAR:
464        case OP_NOTSTARI:
465        case OP_MINSTAR:
466        case OP_MINSTARI:
467        case OP_NOTMINSTAR:
468        case OP_NOTMINSTARI:
469        case OP_POSSTAR:
470        case OP_POSSTARI:
471        case OP_NOTPOSSTAR:
472        case OP_NOTPOSSTARI:
473    
474        case OP_QUERY:
475        case OP_QUERYI:
476        case OP_NOTQUERY:
477        case OP_NOTQUERYI:
478        case OP_MINQUERY:
479        case OP_MINQUERYI:
480        case OP_NOTMINQUERY:
481        case OP_NOTMINQUERYI:
482        case OP_POSQUERY:
483        case OP_POSQUERYI:
484        case OP_NOTPOSQUERY:
485        case OP_NOTPOSQUERYI:
486    
487        cc += _pcre_OP_lengths[op];
488    #ifdef SUPPORT_UTF8
489        if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];
490    #endif
491        break;
492    
493        /* Skip these, but we need to add in the name length. */
494    
495        case OP_MARK:
496        case OP_PRUNE_ARG:
497        case OP_SKIP_ARG:
498        cc += _pcre_OP_lengths[op] + cc[1];
499        break;
500    
501        case OP_THEN_ARG:
502        cc += _pcre_OP_lengths[op] + cc[1+LINK_SIZE];
503        break;
504    
505        /* The remaining opcodes are just skipped over. */
506    
507        case OP_CLOSE:
508        case OP_COMMIT:
509        case OP_FAIL:
510        case OP_PRUNE:
511        case OP_SET_SOM:
512        case OP_SKIP:
513        case OP_THEN:
514        cc += _pcre_OP_lengths[op];
515        break;
516    
517        /* This should not occur: we list all opcodes explicitly so that when
518        new ones get added they are properly considered. */
519    
520        default:
521        return -3;
522        }
523      }
524    /* Control never gets here */
525    }
526    
527    
528    
529  /*************************************************  /*************************************************
530  *      Set a bit and maybe its alternate case    *  *      Set a bit and maybe its alternate case    *
531  *************************************************/  *************************************************/
532    
533  /* Given a character, set its bit in the table, and also the bit for the other  /* Given a character, set its first byte's bit in the table, and also the
534  version of a letter if we are caseless.  corresponding bit for the other version of a letter if we are caseless. In
535    UTF-8 mode, for characters greater than 127, we can only do the caseless thing
536    when Unicode property support is available.
537    
538  Arguments:  Arguments:
539    start_bits    points to the bit map    start_bits    points to the bit map
540    c             is the character    p             points to the character
541    caseless      the caseless flag    caseless      the caseless flag
542    cd            the block with char table pointers    cd            the block with char table pointers
543      utf8          TRUE for UTF-8 mode
544    
545    Returns:        pointer after the character
546    */
547    
548    static const uschar *
549    set_table_bit(uschar *start_bits, const uschar *p, BOOL caseless,
550      compile_data *cd, BOOL utf8)
551    {
552    unsigned int c = *p;
553    
554    SET_BIT(c);
555    
556    #ifdef SUPPORT_UTF8
557    if (utf8 && c > 127)
558      {
559      GETCHARINC(c, p);
560    #ifdef SUPPORT_UCP
561      if (caseless)
562        {
563        uschar buff[8];
564        c = UCD_OTHERCASE(c);
565        (void)_pcre_ord2utf8(c, buff);
566        SET_BIT(buff[0]);
567        }
568    #endif
569      return p;
570      }
571    #endif
572    
573    /* Not UTF-8 mode, or character is less than 127. */
574    
575    if (caseless && (cd->ctypes[c] & ctype_letter) != 0) SET_BIT(cd->fcc[c]);
576    return p + 1;
577    }
578    
579    
580    
581    /*************************************************
582    *     Set bits for a positive character type     *
583    *************************************************/
584    
585    /* This function sets starting bits for a character type. In UTF-8 mode, we can
586    only do a direct setting for bytes less than 128, as otherwise there can be
587    confusion with bytes in the middle of UTF-8 characters. In a "traditional"
588    environment, the tables will only recognize ASCII characters anyway, but in at
589    least one Windows environment, some higher bytes bits were set in the tables.
590    So we deal with that case by considering the UTF-8 encoding.
591    
592    Arguments:
593      start_bits     the starting bitmap
594      cbit type      the type of character wanted
595      table_limit    32 for non-UTF-8; 16 for UTF-8
596      cd             the block with char table pointers
597    
598    Returns:         nothing
599    */
600    
601    static void
602    set_type_bits(uschar *start_bits, int cbit_type, int table_limit,
603      compile_data *cd)
604    {
605    register int c;
606    for (c = 0; c < table_limit; c++) start_bits[c] |= cd->cbits[c+cbit_type];
607    if (table_limit == 32) return;
608    for (c = 128; c < 256; c++)
609      {
610      if ((cd->cbits[c/8] & (1 << (c&7))) != 0)
611        {
612        uschar buff[8];
613        (void)_pcre_ord2utf8(c, buff);
614        SET_BIT(buff[0]);
615        }
616      }
617    }
618    
619    
620  Returns:        nothing  /*************************************************
621    *     Set bits for a negative character type     *
622    *************************************************/
623    
624    /* This function sets starting bits for a negative character type such as \D.
625    In UTF-8 mode, we can only do a direct setting for bytes less than 128, as
626    otherwise there can be confusion with bytes in the middle of UTF-8 characters.
627    Unlike in the positive case, where we can set appropriate starting bits for
628    specific high-valued UTF-8 characters, in this case we have to set the bits for
629    all high-valued characters. The lowest is 0xc2, but we overkill by starting at
630    0xc0 (192) for simplicity.
631    
632    Arguments:
633      start_bits     the starting bitmap
634      cbit type      the type of character wanted
635      table_limit    32 for non-UTF-8; 16 for UTF-8
636      cd             the block with char table pointers
637    
638    Returns:         nothing
639  */  */
640    
641  static void  static void
642  set_bit(uschar *start_bits, unsigned int c, BOOL caseless, compile_data *cd)  set_nottype_bits(uschar *start_bits, int cbit_type, int table_limit,
643      compile_data *cd)
644  {  {
645  start_bits[c/8] |= (1 << (c&7));  register int c;
646  if (caseless && (cd->ctypes[c] & ctype_letter) != 0)  for (c = 0; c < table_limit; c++) start_bits[c] |= ~cd->cbits[c+cbit_type];
647    start_bits[cd->fcc[c]/8] |= (1 << (cd->fcc[c]&7));  if (table_limit != 32) for (c = 24; c < 32; c++) start_bits[c] = 0xff;
648  }  }
649    
650    
651    
652  /*************************************************  /*************************************************
653  *          Create bitmap of starting chars       *  *          Create bitmap of starting bytes       *
654  *************************************************/  *************************************************/
655    
656  /* This function scans a compiled unanchored expression and attempts to build a  /* This function scans a compiled unanchored expression recursively and
657  bitmap of the set of initial characters. If it can't, it returns FALSE. As time  attempts to build a bitmap of the set of possible starting bytes. As time goes
658  goes by, we may be able to get more clever at doing this.  by, we may be able to get more clever at doing this. The SSB_CONTINUE return is
659    useful for parenthesized groups in patterns such as (a*)b where the group
660    provides some optional starting bytes but scanning must continue at the outer
661    level to find at least one mandatory byte. At the outermost level, this
662    function fails unless the result is SSB_DONE.
663    
664  Arguments:  Arguments:
665    code         points to an expression    code         points to an expression
666    start_bits   points to a 32-byte table, initialized to 0    start_bits   points to a 32-byte table, initialized to 0
   caseless     the current state of the caseless flag  
667    utf8         TRUE if in UTF-8 mode    utf8         TRUE if in UTF-8 mode
668    cd           the block with char table pointers    cd           the block with char table pointers
669    
670  Returns:       TRUE if table built, FALSE otherwise  Returns:       SSB_FAIL     => Failed to find any starting bytes
671                   SSB_DONE     => Found mandatory starting bytes
672                   SSB_CONTINUE => Found optional starting bytes
673                   SSB_UNKNOWN  => Hit an unrecognized opcode
674  */  */
675    
676  static BOOL  static int
677  set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless,  set_start_bits(const uschar *code, uschar *start_bits, BOOL utf8,
678    BOOL utf8, compile_data *cd)    compile_data *cd)
679  {  {
680  register int c;  register int c;
681    int yield = SSB_DONE;
682    int table_limit = utf8? 16:32;
683    
684    #if 0
685    /* ========================================================================= */
686    /* The following comment and code was inserted in January 1999. In May 2006,
687    when it was observed to cause compiler warnings about unused values, I took it
688    out again. If anybody is still using OS/2, they will have to put it back
689    manually. */
690    
691  /* This next statement and the later reference to dummy are here in order to  /* This next statement and the later reference to dummy are here in order to
692  trick the optimizer of the IBM C compiler for OS/2 into generating correct  trick the optimizer of the IBM C compiler for OS/2 into generating correct
# Line 102  disable optimization (in this module it Line 695  disable optimization (in this module it
695  the pcre module can use all the optimization it can get). */  the pcre module can use all the optimization it can get). */
696    
697  volatile int dummy;  volatile int dummy;
698    /* ========================================================================= */
699    #endif
700    
701  do  do
702    {    {
   const uschar *tcode = code + 1 + LINK_SIZE;  
703    BOOL try_next = TRUE;    BOOL try_next = TRUE;
704      const uschar *tcode = code + 1 + LINK_SIZE;
705    
706    while (try_next)    if (*code == OP_CBRA || *code == OP_SCBRA ||
707          *code == OP_CBRAPOS || *code == OP_SCBRAPOS) tcode += 2;
708    
709      while (try_next)    /* Loop for items in this branch */
710      {      {
711      /* If a branch starts with a bracket or a positive lookahead assertion,      int rc;
     recurse to set bits from within them. That's all for this branch. */  
712    
713      if ((int)*tcode >= OP_BRA || *tcode == OP_ASSERT)      switch(*tcode)
714        {        {
715        if (!set_start_bits(tcode, start_bits, caseless, utf8, cd))        /* If we reach something we don't understand, it means a new opcode has
716          return FALSE;        been created that hasn't been added to this code. Hopefully this problem
717        try_next = FALSE;        will be discovered during testing. */
       }  
718    
     else switch(*tcode)  
       {  
719        default:        default:
720        return FALSE;        return SSB_UNKNOWN;
721    
722        /* Skip over callout */        /* Fail for a valid opcode that implies no starting bits. */
723    
724        case OP_CALLOUT:        case OP_ACCEPT:
725        tcode += 2 + 2*LINK_SIZE;        case OP_ASSERT_ACCEPT:
726          case OP_ALLANY:
727          case OP_ANY:
728          case OP_ANYBYTE:
729          case OP_CIRC:
730          case OP_CIRCM:
731          case OP_CLOSE:
732          case OP_COMMIT:
733          case OP_COND:
734          case OP_CREF:
735          case OP_DEF:
736          case OP_DOLL:
737          case OP_DOLLM:
738          case OP_END:
739          case OP_EOD:
740          case OP_EODN:
741          case OP_EXTUNI:
742          case OP_FAIL:
743          case OP_MARK:
744          case OP_NCREF:
745          case OP_NOT:
746          case OP_NOTEXACT:
747          case OP_NOTEXACTI:
748          case OP_NOTI:
749          case OP_NOTMINPLUS:
750          case OP_NOTMINPLUSI:
751          case OP_NOTMINQUERY:
752          case OP_NOTMINQUERYI:
753          case OP_NOTMINSTAR:
754          case OP_NOTMINSTARI:
755          case OP_NOTMINUPTO:
756          case OP_NOTMINUPTOI:
757          case OP_NOTPLUS:
758          case OP_NOTPLUSI:
759          case OP_NOTPOSPLUS:
760          case OP_NOTPOSPLUSI:
761          case OP_NOTPOSQUERY:
762          case OP_NOTPOSQUERYI:
763          case OP_NOTPOSSTAR:
764          case OP_NOTPOSSTARI:
765          case OP_NOTPOSUPTO:
766          case OP_NOTPOSUPTOI:
767          case OP_NOTPROP:
768          case OP_NOTQUERY:
769          case OP_NOTQUERYI:
770          case OP_NOTSTAR:
771          case OP_NOTSTARI:
772          case OP_NOTUPTO:
773          case OP_NOTUPTOI:
774          case OP_NOT_HSPACE:
775          case OP_NOT_VSPACE:
776          case OP_NRREF:
777          case OP_PROP:
778          case OP_PRUNE:
779          case OP_PRUNE_ARG:
780          case OP_RECURSE:
781          case OP_REF:
782          case OP_REFI:
783          case OP_REVERSE:
784          case OP_RREF:
785          case OP_SCOND:
786          case OP_SET_SOM:
787          case OP_SKIP:
788          case OP_SKIP_ARG:
789          case OP_SOD:
790          case OP_SOM:
791          case OP_THEN:
792          case OP_THEN_ARG:
793          case OP_XCLASS:
794          return SSB_FAIL;
795    
796          /* We can ignore word boundary tests. */
797    
798          case OP_WORD_BOUNDARY:
799          case OP_NOT_WORD_BOUNDARY:
800          tcode++;
801          break;
802    
803          /* If we hit a bracket or a positive lookahead assertion, recurse to set
804          bits from within the subpattern. If it can't find anything, we have to
805          give up. If it finds some mandatory character(s), we are done for this
806          branch. Otherwise, carry on scanning after the subpattern. */
807    
808          case OP_BRA:
809          case OP_SBRA:
810          case OP_CBRA:
811          case OP_SCBRA:
812          case OP_BRAPOS:
813          case OP_SBRAPOS:
814          case OP_CBRAPOS:
815          case OP_SCBRAPOS:
816          case OP_ONCE:
817          case OP_ASSERT:
818          rc = set_start_bits(tcode, start_bits, utf8, cd);
819          if (rc == SSB_FAIL || rc == SSB_UNKNOWN) return rc;
820          if (rc == SSB_DONE) try_next = FALSE; else
821            {
822            do tcode += GET(tcode, 1); while (*tcode == OP_ALT);
823            tcode += 1 + LINK_SIZE;
824            }
825        break;        break;
826    
827        /* Skip over extended extraction bracket number */        /* If we hit ALT or KET, it means we haven't found anything mandatory in
828          this branch, though we might have found something optional. For ALT, we
829          continue with the next alternative, but we have to arrange that the final
830          result from subpattern is SSB_CONTINUE rather than SSB_DONE. For KET,
831          return SSB_CONTINUE: if this is the top level, that indicates failure,
832          but after a nested subpattern, it causes scanning to continue. */
833    
834        case OP_BRANUMBER:        case OP_ALT:
835        tcode += 3;        yield = SSB_CONTINUE;
836          try_next = FALSE;
837          break;
838    
839          case OP_KET:
840          case OP_KETRMAX:
841          case OP_KETRMIN:
842          case OP_KETRPOS:
843          return SSB_CONTINUE;
844    
845          /* Skip over callout */
846    
847          case OP_CALLOUT:
848          tcode += 2 + 2*LINK_SIZE;
849        break;        break;
850    
851        /* Skip over lookbehind and negative lookahead assertions */        /* Skip over lookbehind and negative lookahead assertions */
# Line 143  do Line 854  do
854        case OP_ASSERTBACK:        case OP_ASSERTBACK:
855        case OP_ASSERTBACK_NOT:        case OP_ASSERTBACK_NOT:
856        do tcode += GET(tcode, 1); while (*tcode == OP_ALT);        do tcode += GET(tcode, 1); while (*tcode == OP_ALT);
857        tcode += 1+LINK_SIZE;        tcode += 1 + LINK_SIZE;
       break;  
   
       /* Skip over an option setting, changing the caseless flag */  
   
       case OP_OPT:  
       caseless = (tcode[1] & PCRE_CASELESS) != 0;  
       tcode += 2;  
858        break;        break;
859    
860        /* BRAZERO does the bracket, but carries on. */        /* BRAZERO does the bracket, but carries on. */
861    
862        case OP_BRAZERO:        case OP_BRAZERO:
863        case OP_BRAMINZERO:        case OP_BRAMINZERO:
864        if (!set_start_bits(++tcode, start_bits, caseless, utf8, cd))        case OP_BRAPOSZERO:
865          return FALSE;        rc = set_start_bits(++tcode, start_bits, utf8, cd);
866          if (rc == SSB_FAIL || rc == SSB_UNKNOWN) return rc;
867    /* =========================================================================
868          See the comment at the head of this function concerning the next line,
869          which was an old fudge for the benefit of OS/2.
870        dummy = 1;        dummy = 1;
871      ========================================================================= */
872          do tcode += GET(tcode,1); while (*tcode == OP_ALT);
873          tcode += 1 + LINK_SIZE;
874          break;
875    
876          /* SKIPZERO skips the bracket. */
877    
878          case OP_SKIPZERO:
879          tcode++;
880        do tcode += GET(tcode,1); while (*tcode == OP_ALT);        do tcode += GET(tcode,1); while (*tcode == OP_ALT);
881        tcode += 1+LINK_SIZE;        tcode += 1 + LINK_SIZE;
882        break;        break;
883    
884        /* Single-char * or ? sets the bit and tries the next item */        /* Single-char * or ? sets the bit and tries the next item */
885    
886        case OP_STAR:        case OP_STAR:
887        case OP_MINSTAR:        case OP_MINSTAR:
888          case OP_POSSTAR:
889        case OP_QUERY:        case OP_QUERY:
890        case OP_MINQUERY:        case OP_MINQUERY:
891        set_bit(start_bits, tcode[1], caseless, cd);        case OP_POSQUERY:
892        tcode += 2;        tcode = set_table_bit(start_bits, tcode + 1, FALSE, cd, utf8);
893  #ifdef SUPPORT_UTF8        break;
894        if (utf8) while ((*tcode & 0xc0) == 0x80) tcode++;  
895  #endif        case OP_STARI:
896          case OP_MINSTARI:
897          case OP_POSSTARI:
898          case OP_QUERYI:
899          case OP_MINQUERYI:
900          case OP_POSQUERYI:
901          tcode = set_table_bit(start_bits, tcode + 1, TRUE, cd, utf8);
902        break;        break;
903    
904        /* Single-char upto sets the bit and tries the next */        /* Single-char upto sets the bit and tries the next */
905    
906        case OP_UPTO:        case OP_UPTO:
907        case OP_MINUPTO:        case OP_MINUPTO:
908        set_bit(start_bits, tcode[3], caseless, cd);        case OP_POSUPTO:
909        tcode += 4;        tcode = set_table_bit(start_bits, tcode + 3, FALSE, cd, utf8);
910  #ifdef SUPPORT_UTF8        break;
911        if (utf8) while ((*tcode & 0xc0) == 0x80) tcode++;  
912  #endif        case OP_UPTOI:
913          case OP_MINUPTOI:
914          case OP_POSUPTOI:
915          tcode = set_table_bit(start_bits, tcode + 3, TRUE, cd, utf8);
916        break;        break;
917    
918        /* At least one single char sets the bit and stops */        /* At least one single char sets the bit and stops */
919    
920        case OP_EXACT:       /* Fall through */        case OP_EXACT:
921        tcode += 2;        tcode += 2;
922          /* Fall through */
923        case OP_CHAR:        case OP_CHAR:
       case OP_CHARNC:  
924        case OP_PLUS:        case OP_PLUS:
925        case OP_MINPLUS:        case OP_MINPLUS:
926        set_bit(start_bits, tcode[1], caseless, cd);        case OP_POSPLUS:
927          (void)set_table_bit(start_bits, tcode + 1, FALSE, cd, utf8);
928        try_next = FALSE;        try_next = FALSE;
929        break;        break;
930    
931        /* Single character type sets the bits and stops */        case OP_EXACTI:
932          tcode += 2;
933          /* Fall through */
934          case OP_CHARI:
935          case OP_PLUSI:
936          case OP_MINPLUSI:
937          case OP_POSPLUSI:
938          (void)set_table_bit(start_bits, tcode + 1, TRUE, cd, utf8);
939          try_next = FALSE;
940          break;
941    
942          /* Special spacing and line-terminating items. These recognize specific
943          lists of characters. The difference between VSPACE and ANYNL is that the
944          latter can match the two-character CRLF sequence, but that is not
945          relevant for finding the first character, so their code here is
946          identical. */
947    
948          case OP_HSPACE:
949          SET_BIT(0x09);
950          SET_BIT(0x20);
951          if (utf8)
952            {
953            SET_BIT(0xC2);  /* For U+00A0 */
954            SET_BIT(0xE1);  /* For U+1680, U+180E */
955            SET_BIT(0xE2);  /* For U+2000 - U+200A, U+202F, U+205F */
956            SET_BIT(0xE3);  /* For U+3000 */
957            }
958          else SET_BIT(0xA0);
959          try_next = FALSE;
960          break;
961    
962          case OP_ANYNL:
963          case OP_VSPACE:
964          SET_BIT(0x0A);
965          SET_BIT(0x0B);
966          SET_BIT(0x0C);
967          SET_BIT(0x0D);
968          if (utf8)
969            {
970            SET_BIT(0xC2);  /* For U+0085 */
971            SET_BIT(0xE2);  /* For U+2028, U+2029 */
972            }
973          else SET_BIT(0x85);
974          try_next = FALSE;
975          break;
976    
977          /* Single character types set the bits and stop. Note that if PCRE_UCP
978          is set, we do not see these op codes because \d etc are converted to
979          properties. Therefore, these apply in the case when only characters less
980          than 256 are recognized to match the types. */
981    
982        case OP_NOT_DIGIT:        case OP_NOT_DIGIT:
983        for (c = 0; c < 32; c++)        set_nottype_bits(start_bits, cbit_digit, table_limit, cd);
         start_bits[c] |= ~cd->cbits[c+cbit_digit];  
984        try_next = FALSE;        try_next = FALSE;
985        break;        break;
986    
987        case OP_DIGIT:        case OP_DIGIT:
988        for (c = 0; c < 32; c++)        set_type_bits(start_bits, cbit_digit, table_limit, cd);
         start_bits[c] |= cd->cbits[c+cbit_digit];  
989        try_next = FALSE;        try_next = FALSE;
990        break;        break;
991    
992          /* The cbit_space table has vertical tab as whitespace; we have to
993          ensure it is set as not whitespace. */
994    
995        case OP_NOT_WHITESPACE:        case OP_NOT_WHITESPACE:
996        for (c = 0; c < 32; c++)        set_nottype_bits(start_bits, cbit_space, table_limit, cd);
997          start_bits[c] |= ~cd->cbits[c+cbit_space];        start_bits[1] |= 0x08;
998        try_next = FALSE;        try_next = FALSE;
999        break;        break;
1000    
1001          /* The cbit_space table has vertical tab as whitespace; we have to
1002          not set it from the table. */
1003    
1004        case OP_WHITESPACE:        case OP_WHITESPACE:
1005        for (c = 0; c < 32; c++)        c = start_bits[1];    /* Save in case it was already set */
1006          start_bits[c] |= cd->cbits[c+cbit_space];        set_type_bits(start_bits, cbit_space, table_limit, cd);
1007          start_bits[1] = (start_bits[1] & ~0x08) | c;
1008        try_next = FALSE;        try_next = FALSE;
1009        break;        break;
1010    
1011        case OP_NOT_WORDCHAR:        case OP_NOT_WORDCHAR:
1012        for (c = 0; c < 32; c++)        set_nottype_bits(start_bits, cbit_word, table_limit, cd);
         start_bits[c] |= ~cd->cbits[c+cbit_word];  
1013        try_next = FALSE;        try_next = FALSE;
1014        break;        break;
1015    
1016        case OP_WORDCHAR:        case OP_WORDCHAR:
1017        for (c = 0; c < 32; c++)        set_type_bits(start_bits, cbit_word, table_limit, cd);
         start_bits[c] |= cd->cbits[c+cbit_word];  
1018        try_next = FALSE;        try_next = FALSE;
1019        break;        break;
1020    
# Line 244  do Line 1023  do
1023    
1024        case OP_TYPEPLUS:        case OP_TYPEPLUS:
1025        case OP_TYPEMINPLUS:        case OP_TYPEMINPLUS:
1026          case OP_TYPEPOSPLUS:
1027        tcode++;        tcode++;
1028        break;        break;
1029    
# Line 256  do Line 1036  do
1036    
1037        case OP_TYPEUPTO:        case OP_TYPEUPTO:
1038        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
1039          case OP_TYPEPOSUPTO:
1040        tcode += 2;               /* Fall through */        tcode += 2;               /* Fall through */
1041    
1042        case OP_TYPESTAR:        case OP_TYPESTAR:
1043        case OP_TYPEMINSTAR:        case OP_TYPEMINSTAR:
1044          case OP_TYPEPOSSTAR:
1045        case OP_TYPEQUERY:        case OP_TYPEQUERY:
1046        case OP_TYPEMINQUERY:        case OP_TYPEMINQUERY:
1047          case OP_TYPEPOSQUERY:
1048        switch(tcode[1])        switch(tcode[1])
1049          {          {
1050            default:
1051          case OP_ANY:          case OP_ANY:
1052          return FALSE;          case OP_ALLANY:
1053            return SSB_FAIL;
1054    
1055            case OP_HSPACE:
1056            SET_BIT(0x09);
1057            SET_BIT(0x20);
1058            if (utf8)
1059              {
1060              SET_BIT(0xC2);  /* For U+00A0 */
1061              SET_BIT(0xE1);  /* For U+1680, U+180E */
1062              SET_BIT(0xE2);  /* For U+2000 - U+200A, U+202F, U+205F */
1063              SET_BIT(0xE3);  /* For U+3000 */
1064              }
1065            else SET_BIT(0xA0);
1066            break;
1067    
1068            case OP_ANYNL:
1069            case OP_VSPACE:
1070            SET_BIT(0x0A);
1071            SET_BIT(0x0B);
1072            SET_BIT(0x0C);
1073            SET_BIT(0x0D);
1074            if (utf8)
1075              {
1076              SET_BIT(0xC2);  /* For U+0085 */
1077              SET_BIT(0xE2);  /* For U+2028, U+2029 */
1078              }
1079            else SET_BIT(0x85);
1080            break;
1081    
1082          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
1083          for (c = 0; c < 32; c++)          set_nottype_bits(start_bits, cbit_digit, table_limit, cd);
           start_bits[c] |= ~cd->cbits[c+cbit_digit];  
1084          break;          break;
1085    
1086          case OP_DIGIT:          case OP_DIGIT:
1087          for (c = 0; c < 32; c++)          set_type_bits(start_bits, cbit_digit, table_limit, cd);
           start_bits[c] |= cd->cbits[c+cbit_digit];  
1088          break;          break;
1089    
1090            /* The cbit_space table has vertical tab as whitespace; we have to
1091            ensure it gets set as not whitespace. */
1092    
1093          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
1094          for (c = 0; c < 32; c++)          set_nottype_bits(start_bits, cbit_space, table_limit, cd);
1095            start_bits[c] |= ~cd->cbits[c+cbit_space];          start_bits[1] |= 0x08;
1096          break;          break;
1097    
1098            /* The cbit_space table has vertical tab as whitespace; we have to
1099            avoid setting it. */
1100    
1101          case OP_WHITESPACE:          case OP_WHITESPACE:
1102          for (c = 0; c < 32; c++)          c = start_bits[1];    /* Save in case it was already set */
1103            start_bits[c] |= cd->cbits[c+cbit_space];          set_type_bits(start_bits, cbit_space, table_limit, cd);
1104            start_bits[1] = (start_bits[1] & ~0x08) | c;
1105          break;          break;
1106    
1107          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
1108          for (c = 0; c < 32; c++)          set_nottype_bits(start_bits, cbit_word, table_limit, cd);
           start_bits[c] |= ~cd->cbits[c+cbit_word];  
1109          break;          break;
1110    
1111          case OP_WORDCHAR:          case OP_WORDCHAR:
1112          for (c = 0; c < 32; c++)          set_type_bits(start_bits, cbit_word, table_limit, cd);
           start_bits[c] |= cd->cbits[c+cbit_word];  
1113          break;          break;
1114          }          }
1115    
# Line 308  do Line 1123  do
1123        character with a value > 255. */        character with a value > 255. */
1124    
1125        case OP_NCLASS:        case OP_NCLASS:
1126    #ifdef SUPPORT_UTF8
1127        if (utf8)        if (utf8)
1128          {          {
1129          start_bits[24] |= 0xf0;              /* Bits for 0xc4 - 0xc8 */          start_bits[24] |= 0xf0;              /* Bits for 0xc4 - 0xc8 */
1130          memset(start_bits+25, 0xff, 7);      /* Bits for 0xc9 - 0xff */          memset(start_bits+25, 0xff, 7);      /* Bits for 0xc9 - 0xff */
1131          }          }
1132    #endif
1133        /* Fall through */        /* Fall through */
1134    
1135        case OP_CLASS:        case OP_CLASS:
# Line 325  do Line 1142  do
1142          value is > 127. In fact, there are only two possible starting bytes for          value is > 127. In fact, there are only two possible starting bytes for
1143          characters in the range 128 - 255. */          characters in the range 128 - 255. */
1144    
1145    #ifdef SUPPORT_UTF8
1146          if (utf8)          if (utf8)
1147            {            {
1148            for (c = 0; c < 16; c++) start_bits[c] |= tcode[c];            for (c = 0; c < 16; c++) start_bits[c] |= tcode[c];
# Line 342  do Line 1160  do
1160          /* In non-UTF-8 mode, the two bit maps are completely compatible. */          /* In non-UTF-8 mode, the two bit maps are completely compatible. */
1161    
1162          else          else
1163    #endif
1164            {            {
1165            for (c = 0; c < 32; c++) start_bits[c] |= tcode[c];            for (c = 0; c < 32; c++) start_bits[c] |= tcode[c];
1166            }            }
1167    
1168          /* Advance past the bit map, and act on what follows */          /* Advance past the bit map, and act on what follows. For a zero
1169            minimum repeat, continue; otherwise stop processing. */
1170    
1171          tcode += 32;          tcode += 32;
1172          switch (*tcode)          switch (*tcode)
# Line 377  do Line 1197  do
1197    code += GET(code, 1);   /* Advance to next branch */    code += GET(code, 1);   /* Advance to next branch */
1198    }    }
1199  while (*code == OP_ALT);  while (*code == OP_ALT);
1200  return TRUE;  return yield;
1201  }  }
1202    
1203    
1204    
1205    
1206    
1207  /*************************************************  /*************************************************
1208  *          Study a compiled expression           *  *          Study a compiled expression           *
1209  *************************************************/  *************************************************/
# Line 397  Arguments: Line 1219  Arguments:
1219              set NULL unless error              set NULL unless error
1220    
1221  Returns:    pointer to a pcre_extra block, with study_data filled in and the  Returns:    pointer to a pcre_extra block, with study_data filled in and the
1222                appropriate flag set;                appropriate flags set;
1223              NULL on error or if no optimization possible              NULL on error or if no optimization possible
1224  */  */
1225    
1226  PCRE_DATA_SCOPE pcre_extra *  PCRE_EXP_DEFN pcre_extra * PCRE_CALL_CONVENTION
1227  pcre_study(const pcre *external_re, int options, const char **errorptr)  pcre_study(const pcre *external_re, int options, const char **errorptr)
1228  {  {
1229    int min;
1230    BOOL bits_set = FALSE;
1231    BOOL had_accept = FALSE;
1232  uschar start_bits[32];  uschar start_bits[32];
1233  pcre_extra *extra;  pcre_extra *extra;
1234  pcre_study_data *study;  pcre_study_data *study;
1235  const uschar *tables;  const uschar *tables;
1236  const real_pcre *re = (const real_pcre *)external_re;  uschar *code;
 uschar *code = (uschar *)re + re->name_table_offset +  
   (re->name_count * re->name_entry_size);  
1237  compile_data compile_block;  compile_data compile_block;
1238    const real_pcre *re = (const real_pcre *)external_re;
1239    
1240  *errorptr = NULL;  *errorptr = NULL;
1241    
# Line 427  if ((options & ~PUBLIC_STUDY_OPTIONS) != Line 1251  if ((options & ~PUBLIC_STUDY_OPTIONS) !=
1251    return NULL;    return NULL;
1252    }    }
1253    
1254    code = (uschar *)re + re->name_table_offset +
1255      (re->name_count * re->name_entry_size);
1256    
1257  /* For an anchored pattern, or an unanchored pattern that has a first char, or  /* For an anchored pattern, or an unanchored pattern that has a first char, or
1258  a multiline pattern that matches only at "line starts", no further processing  a multiline pattern that matches only at "line starts", there is no point in
1259  at present. */  seeking a list of starting bytes. */
1260    
1261  if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0)  if ((re->options & PCRE_ANCHORED) == 0 &&
1262    return NULL;      (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) == 0)
1263      {
1264      int rc;
1265    
1266      /* Set the character tables in the block that is passed around */
1267    
1268      tables = re->tables;
1269      if (tables == NULL)
1270        (void)pcre_fullinfo(external_re, NULL, PCRE_INFO_DEFAULT_TABLES,
1271        (void *)(&tables));
1272    
1273      compile_block.lcc = tables + lcc_offset;
1274      compile_block.fcc = tables + fcc_offset;
1275      compile_block.cbits = tables + cbits_offset;
1276      compile_block.ctypes = tables + ctypes_offset;
1277    
1278      /* See if we can find a fixed set of initial characters for the pattern. */
1279    
1280      memset(start_bits, 0, 32 * sizeof(uschar));
1281      rc = set_start_bits(code, start_bits, (re->options & PCRE_UTF8) != 0,
1282        &compile_block);
1283      bits_set = rc == SSB_DONE;
1284      if (rc == SSB_UNKNOWN) *errorptr = "internal error: opcode not recognized";
1285      }
1286    
1287    /* Find the minimum length of subject string. */
1288    
1289    switch(min = find_minlength(code, code, re->options, &had_accept, 0))
1290      {
1291      case -2: *errorptr = "internal error: missing capturing bracket"; break;
1292      case -3: *errorptr = "internal error: opcode not recognized"; break;
1293      default: break;
1294      }
1295    
1296  /* Set the character tables in the block that is passed around */  /* Return NULL if there's been an error or if no optimization is possible. */
1297    
1298  tables = re->tables;  if (*errorptr != NULL || (!bits_set && min < 0)) return NULL;
 if (tables == NULL)  
   (void)pcre_fullinfo(external_re, NULL, PCRE_INFO_DEFAULT_TABLES,  
   (void *)(&tables));  
   
 compile_block.lcc = tables + lcc_offset;  
 compile_block.fcc = tables + fcc_offset;  
 compile_block.cbits = tables + cbits_offset;  
 compile_block.ctypes = tables + ctypes_offset;  
   
 /* See if we can find a fixed set of initial characters for the pattern. */  
   
 memset(start_bits, 0, 32 * sizeof(uschar));  
 if (!set_start_bits(code, start_bits, (re->options & PCRE_CASELESS) != 0,  
   (re->options & PCRE_UTF8) != 0, &compile_block)) return NULL;  
1299    
1300  /* Get a pcre_extra block and a pcre_study_data block. The study data is put in  /* Get a pcre_extra block and a pcre_study_data block. The study data is put in
1301  the latter, which is pointed to by the former, which may also get additional  the latter, which is pointed to by the former, which may also get additional
# Line 473  extra->flags = PCRE_EXTRA_STUDY_DATA; Line 1318  extra->flags = PCRE_EXTRA_STUDY_DATA;
1318  extra->study_data = study;  extra->study_data = study;
1319    
1320  study->size = sizeof(pcre_study_data);  study->size = sizeof(pcre_study_data);
1321  study->options = PCRE_STUDY_MAPPED;  study->flags = 0;
1322  memcpy(study->start_bits, start_bits, sizeof(start_bits));  
1323    if (bits_set)
1324      {
1325      study->flags |= PCRE_STUDY_MAPPED;
1326      memcpy(study->start_bits, start_bits, sizeof(start_bits));
1327      }
1328    
1329    if (min >= 0)
1330      {
1331      study->flags |= PCRE_STUDY_MINLEN;
1332      study->minlength = min;
1333      }
1334    
1335  return extra;  return extra;
1336  }  }

Legend:
Removed from v.87  
changed lines
  Added in v.657

  ViewVC Help
Powered by ViewVC 1.1.5