/[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 545 by ph10, Wed Jun 16 10:51:15 2010 UTC revision 612 by ph10, Sat Jul 2 15:20:59 2011 UTC
# Line 52  supporting functions. */ Line 52  supporting functions. */
52    
53  /* Returns from set_start_bits() */  /* Returns from set_start_bits() */
54    
55  enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE };  enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE, SSB_UNKNOWN };
56    
57    
58    
# Line 66  string of that length that matches. In U Line 66  string of that length that matches. In U
66  rather than bytes.  rather than bytes.
67    
68  Arguments:  Arguments:
69    code       pointer to start of group (the bracket)    code        pointer to start of group (the bracket)
70    startcode  pointer to start of the whole pattern    startcode   pointer to start of the whole pattern
71    options    the compiling options    options     the compiling options
72      had_accept  pointer to flag for (*ACCEPT) encountered
73    
74  Returns:   the minimum length  Returns:   the minimum length
75             -1 if \C was encountered             -1 if \C was encountered
76             -2 internal error (missing capturing bracket)             -2 internal error (missing capturing bracket)
77               -3 internal error (opcode not listed)
78  */  */
79    
80  static int  static int
81  find_minlength(const uschar *code, const uschar *startcode, int options)  find_minlength(const uschar *code, const uschar *startcode, int options,
82      BOOL *had_accept_ptr)
83  {  {
84  int length = -1;  int length = -1;
85  BOOL utf8 = (options & PCRE_UTF8) != 0;  BOOL utf8 = (options & PCRE_UTF8) != 0;
# Line 84  BOOL had_recurse = FALSE; Line 87  BOOL had_recurse = FALSE;
87  register int branchlength = 0;  register int branchlength = 0;
88  register uschar *cc = (uschar *)code + 1 + LINK_SIZE;  register uschar *cc = (uschar *)code + 1 + LINK_SIZE;
89    
90  if (*code == OP_CBRA || *code == OP_SCBRA) cc += 2;  if (*code == OP_CBRA || *code == OP_SCBRA ||
91        *code == OP_CBRAPOS || *code == OP_SCBRAPOS) cc += 2;
92    
93  /* Scan along the opcodes for this branch. If we get to the end of the  /* Scan along the opcodes for this branch. If we get to the end of the
94  branch, check the length against that of the other branches. */  branch, check the length against that of the other branches. */
# Line 118  for (;;) Line 122  for (;;)
122      case OP_SCBRA:      case OP_SCBRA:
123      case OP_BRA:      case OP_BRA:
124      case OP_SBRA:      case OP_SBRA:
125        case OP_CBRAPOS:
126        case OP_SCBRAPOS:
127        case OP_BRAPOS:
128        case OP_SBRAPOS:
129      case OP_ONCE:      case OP_ONCE:
130      d = find_minlength(cc, startcode, options);      d = find_minlength(cc, startcode, options, had_accept_ptr);
131      if (d < 0) return d;      if (d < 0) return d;
132      branchlength += d;      branchlength += d;
133        if (*had_accept_ptr) return branchlength;
134      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
135      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
136      break;      break;
137    
138      /* Reached end of a branch; if it's a ket it is the end of a nested      /* Reached end of a branch; if it's a ket it is the end of a nested
139      call. If it's ALT it is an alternation in a nested call. If it is      call. If it's ALT it is an alternation in a nested call. If it is END it's
140      END it's the end of the outer call. All can be handled by the same code. */      the end of the outer call. All can be handled by the same code. If it is
141        ACCEPT, it is essentially the same as END, but we set a flag so that
142        counting stops. */
143    
144        case OP_ACCEPT:
145        *had_accept_ptr = TRUE;
146        /* Fall through */
147      case OP_ALT:      case OP_ALT:
148      case OP_KET:      case OP_KET:
149      case OP_KETRMAX:      case OP_KETRMAX:
150      case OP_KETRMIN:      case OP_KETRMIN:
151        case OP_KETRPOS:
152      case OP_END:      case OP_END:
153      if (length < 0 || (!had_recurse && branchlength < length))      if (length < 0 || (!had_recurse && branchlength < length))
154        length = branchlength;        length = branchlength;
155      if (*cc != OP_ALT) return length;      if (op != OP_ALT) return length;
156      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
157      branchlength = 0;      branchlength = 0;
158      had_recurse = FALSE;      had_recurse = FALSE;
# Line 160  for (;;) Line 175  for (;;)
175      case OP_RREF:      case OP_RREF:
176      case OP_NRREF:      case OP_NRREF:
177      case OP_DEF:      case OP_DEF:
     case OP_OPT:  
178      case OP_CALLOUT:      case OP_CALLOUT:
179      case OP_SOD:      case OP_SOD:
180      case OP_SOM:      case OP_SOM:
181      case OP_EOD:      case OP_EOD:
182      case OP_EODN:      case OP_EODN:
183      case OP_CIRC:      case OP_CIRC:
184        case OP_CIRCM:
185      case OP_DOLL:      case OP_DOLL:
186        case OP_DOLLM:
187      case OP_NOT_WORD_BOUNDARY:      case OP_NOT_WORD_BOUNDARY:
188      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
189      cc += _pcre_OP_lengths[*cc];      cc += _pcre_OP_lengths[*cc];
# Line 177  for (;;) Line 193  for (;;)
193    
194      case OP_BRAZERO:      case OP_BRAZERO:
195      case OP_BRAMINZERO:      case OP_BRAMINZERO:
196        case OP_BRAPOSZERO:
197      case OP_SKIPZERO:      case OP_SKIPZERO:
198      cc += _pcre_OP_lengths[*cc];      cc += _pcre_OP_lengths[*cc];
199      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 186  for (;;) Line 203  for (;;)
203      /* Handle literal characters and + repetitions */      /* Handle literal characters and + repetitions */
204    
205      case OP_CHAR:      case OP_CHAR:
206      case OP_CHARNC:      case OP_CHARI:
207      case OP_NOT:      case OP_NOT:
208        case OP_NOTI:
209      case OP_PLUS:      case OP_PLUS:
210        case OP_PLUSI:
211      case OP_MINPLUS:      case OP_MINPLUS:
212        case OP_MINPLUSI:
213      case OP_POSPLUS:      case OP_POSPLUS:
214        case OP_POSPLUSI:
215      case OP_NOTPLUS:      case OP_NOTPLUS:
216        case OP_NOTPLUSI:
217      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
218        case OP_NOTMINPLUSI:
219      case OP_NOTPOSPLUS:      case OP_NOTPOSPLUS:
220        case OP_NOTPOSPLUSI:
221      branchlength++;      branchlength++;
222      cc += 2;      cc += 2;
223  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 212  for (;;) Line 236  for (;;)
236      need to skip over a multibyte character in UTF8 mode.  */      need to skip over a multibyte character in UTF8 mode.  */
237    
238      case OP_EXACT:      case OP_EXACT:
239        case OP_EXACTI:
240      case OP_NOTEXACT:      case OP_NOTEXACT:
241        case OP_NOTEXACTI:
242      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
243      cc += 4;      cc += 4;
244  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 249  for (;;) Line 275  for (;;)
275      cc++;      cc++;
276      break;      break;
277    
278      /* "Any newline" might match two characters */      /* "Any newline" might match two characters, but it also might match just
279        one. */
280    
281      case OP_ANYNL:      case OP_ANYNL:
282      branchlength += 2;      branchlength += 1;
283      cc++;      cc++;
284      break;      break;
285    
# Line 337  for (;;) Line 364  for (;;)
364      that case we must set the minimum length to zero. */      that case we must set the minimum length to zero. */
365    
366      case OP_REF:      case OP_REF:
367        case OP_REFI:
368      if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)      if ((options & PCRE_JAVASCRIPT_COMPAT) == 0)
369        {        {
370        ce = cs = (uschar *)_pcre_find_bracket(startcode, utf8, GET2(cc, 1));        ce = cs = (uschar *)_pcre_find_bracket(startcode, utf8, GET2(cc, 1));
# Line 347  for (;;) Line 375  for (;;)
375          d = 0;          d = 0;
376          had_recurse = TRUE;          had_recurse = TRUE;
377          }          }
378        else d = find_minlength(cs, startcode, options);        else
379            {
380            d = find_minlength(cs, startcode, options, had_accept_ptr);
381            *had_accept_ptr = FALSE;
382            }
383        }        }
384      else d = 0;      else d = 0;
385      cc += 3;      cc += 3;
# Line 364  for (;;) Line 396  for (;;)
396        cc++;        cc++;
397        break;        break;
398    
399          case OP_CRPLUS:
400          case OP_CRMINPLUS:
401          min = 1;
402          cc++;
403          break;
404    
405        case OP_CRRANGE:        case OP_CRRANGE:
406        case OP_CRMINRANGE:        case OP_CRMINRANGE:
407        min = GET2(cc, 1);        min = GET2(cc, 1);
# Line 385  for (;;) Line 423  for (;;)
423      if (cc > cs && cc < ce)      if (cc > cs && cc < ce)
424        had_recurse = TRUE;        had_recurse = TRUE;
425      else      else
426        branchlength += find_minlength(cs, startcode, options);        {
427          branchlength += find_minlength(cs, startcode, options, had_accept_ptr);
428          *had_accept_ptr = FALSE;
429          }
430      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
431      break;      break;
432    
433      /* Anything else does not or need not match a character. We can get the      /* Anything else does not or need not match a character. We can get the
434      item's length from the table, but for those that can match zero occurrences      item's length from the table, but for those that can match zero occurrences
435      of a character, we must take special action for UTF-8 characters. */      of a character, we must take special action for UTF-8 characters. As it
436        happens, the "NOT" versions of these opcodes are used at present only for
437        ASCII characters, so they could be omitted from this list. However, in
438        future that may change, so we include them here so as not to leave a
439        gotcha for a future maintainer. */
440    
441      case OP_UPTO:      case OP_UPTO:
442        case OP_UPTOI:
443      case OP_NOTUPTO:      case OP_NOTUPTO:
444        case OP_NOTUPTOI:
445      case OP_MINUPTO:      case OP_MINUPTO:
446        case OP_MINUPTOI:
447      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
448        case OP_NOTMINUPTOI:
449      case OP_POSUPTO:      case OP_POSUPTO:
450        case OP_POSUPTOI:
451        case OP_NOTPOSUPTO:
452        case OP_NOTPOSUPTOI:
453    
454      case OP_STAR:      case OP_STAR:
455        case OP_STARI:
456        case OP_NOTSTAR:
457        case OP_NOTSTARI:
458      case OP_MINSTAR:      case OP_MINSTAR:
459        case OP_MINSTARI:
460      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
461        case OP_NOTMINSTARI:
462      case OP_POSSTAR:      case OP_POSSTAR:
463        case OP_POSSTARI:
464      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
465        case OP_NOTPOSSTARI:
466    
467      case OP_QUERY:      case OP_QUERY:
468        case OP_QUERYI:
469        case OP_NOTQUERY:
470        case OP_NOTQUERYI:
471      case OP_MINQUERY:      case OP_MINQUERY:
472        case OP_MINQUERYI:
473      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
474        case OP_NOTMINQUERYI:
475      case OP_POSQUERY:      case OP_POSQUERY:
476        case OP_POSQUERYI:
477      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
478        case OP_NOTPOSQUERYI:
479    
480      cc += _pcre_OP_lengths[op];      cc += _pcre_OP_lengths[op];
481  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
482      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];
# Line 419  for (;;) Line 488  for (;;)
488      case OP_MARK:      case OP_MARK:
489      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
490      case OP_SKIP_ARG:      case OP_SKIP_ARG:
     case OP_THEN_ARG:  
491      cc += _pcre_OP_lengths[op] + cc[1];      cc += _pcre_OP_lengths[op] + cc[1];
492      break;      break;
493    
494      /* For the record, these are the opcodes that are matched by "default":      case OP_THEN_ARG:
495      OP_ACCEPT, OP_CLOSE, OP_COMMIT, OP_FAIL, OP_PRUNE, OP_SET_SOM, OP_SKIP,      cc += _pcre_OP_lengths[op] + cc[1+LINK_SIZE];
496      OP_THEN. */      break;
497    
498        /* The remaining opcodes are just skipped over. */
499    
500      default:      case OP_CLOSE:
501        case OP_COMMIT:
502        case OP_FAIL:
503        case OP_PRUNE:
504        case OP_SET_SOM:
505        case OP_SKIP:
506        case OP_THEN:
507      cc += _pcre_OP_lengths[op];      cc += _pcre_OP_lengths[op];
508      break;      break;
509    
510        /* This should not occur: we list all opcodes explicitly so that when
511        new ones get added they are properly considered. */
512    
513        default:
514        return -3;
515      }      }
516    }    }
517  /* Control never gets here */  /* Control never gets here */
# Line 575  function fails unless the result is SSB_ Line 657  function fails unless the result is SSB_
657  Arguments:  Arguments:
658    code         points to an expression    code         points to an expression
659    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  
660    utf8         TRUE if in UTF-8 mode    utf8         TRUE if in UTF-8 mode
661    cd           the block with char table pointers    cd           the block with char table pointers
662    
663  Returns:       SSB_FAIL     => Failed to find any starting bytes  Returns:       SSB_FAIL     => Failed to find any starting bytes
664                 SSB_DONE     => Found mandatory starting bytes                 SSB_DONE     => Found mandatory starting bytes
665                 SSB_CONTINUE => Found optional starting bytes                 SSB_CONTINUE => Found optional starting bytes
666                   SSB_UNKNOWN  => Hit an unrecognized opcode
667  */  */
668    
669  static int  static int
670  set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless,  set_start_bits(const uschar *code, uschar *start_bits, BOOL utf8,
671    BOOL utf8, compile_data *cd)    compile_data *cd)
672  {  {
673  register int c;  register int c;
674  int yield = SSB_DONE;  int yield = SSB_DONE;
# Line 611  volatile int dummy; Line 693  volatile int dummy;
693    
694  do  do
695    {    {
   const uschar *tcode = code + (((int)*code == OP_CBRA)? 3:1) + LINK_SIZE;  
696    BOOL try_next = TRUE;    BOOL try_next = TRUE;
697      const uschar *tcode = code + 1 + LINK_SIZE;
698    
699      if (*code == OP_CBRA || *code == OP_SCBRA ||
700          *code == OP_CBRAPOS || *code == OP_SCBRAPOS) tcode += 2;
701    
702    while (try_next)    /* Loop for items in this branch */    while (try_next)    /* Loop for items in this branch */
703      {      {
704      int rc;      int rc;
705    
706      switch(*tcode)      switch(*tcode)
707        {        {
708        /* Fail if we reach something we don't understand */        /* If we reach something we don't understand, it means a new opcode has
709          been created that hasn't been added to this code. Hopefully this problem
710          will be discovered during testing. */
711    
712        default:        default:
713          return SSB_UNKNOWN;
714    
715          /* Fail for a valid opcode that implies no starting bits. */
716    
717          case OP_ACCEPT:
718          case OP_ALLANY:
719          case OP_ANY:
720          case OP_ANYBYTE:
721          case OP_CIRC:
722          case OP_CIRCM:
723          case OP_CLOSE:
724          case OP_COMMIT:
725          case OP_COND:
726          case OP_CREF:
727          case OP_DEF:
728          case OP_DOLL:
729          case OP_DOLLM:
730          case OP_END:
731          case OP_EOD:
732          case OP_EODN:
733          case OP_EXTUNI:
734          case OP_FAIL:
735          case OP_MARK:
736          case OP_NCREF:
737          case OP_NOT:
738          case OP_NOTEXACT:
739          case OP_NOTEXACTI:
740          case OP_NOTI:
741          case OP_NOTMINPLUS:
742          case OP_NOTMINPLUSI:
743          case OP_NOTMINQUERY:
744          case OP_NOTMINQUERYI:
745          case OP_NOTMINSTAR:
746          case OP_NOTMINSTARI:
747          case OP_NOTMINUPTO:
748          case OP_NOTMINUPTOI:
749          case OP_NOTPLUS:
750          case OP_NOTPLUSI:
751          case OP_NOTPOSPLUS:
752          case OP_NOTPOSPLUSI:
753          case OP_NOTPOSQUERY:
754          case OP_NOTPOSQUERYI:
755          case OP_NOTPOSSTAR:
756          case OP_NOTPOSSTARI:
757          case OP_NOTPOSUPTO:
758          case OP_NOTPOSUPTOI:
759          case OP_NOTPROP:
760          case OP_NOTQUERY:
761          case OP_NOTQUERYI:
762          case OP_NOTSTAR:
763          case OP_NOTSTARI:
764          case OP_NOTUPTO:
765          case OP_NOTUPTOI:
766          case OP_NOT_HSPACE:
767          case OP_NOT_VSPACE:
768          case OP_NOT_WORD_BOUNDARY:
769          case OP_NRREF:
770          case OP_PROP:
771          case OP_PRUNE:
772          case OP_PRUNE_ARG:
773          case OP_RECURSE:
774          case OP_REF:
775          case OP_REFI:
776          case OP_REVERSE:
777          case OP_RREF:
778          case OP_SCOND:
779          case OP_SET_SOM:
780          case OP_SKIP:
781          case OP_SKIP_ARG:
782          case OP_SOD:
783          case OP_SOM:
784          case OP_THEN:
785          case OP_THEN_ARG:
786          case OP_WORD_BOUNDARY:
787          case OP_XCLASS:
788        return SSB_FAIL;        return SSB_FAIL;
789    
790        /* If we hit a bracket or a positive lookahead assertion, recurse to set        /* If we hit a bracket or a positive lookahead assertion, recurse to set
# Line 633  do Line 796  do
796        case OP_SBRA:        case OP_SBRA:
797        case OP_CBRA:        case OP_CBRA:
798        case OP_SCBRA:        case OP_SCBRA:
799          case OP_BRAPOS:
800          case OP_SBRAPOS:
801          case OP_CBRAPOS:
802          case OP_SCBRAPOS:
803        case OP_ONCE:        case OP_ONCE:
804        case OP_ASSERT:        case OP_ASSERT:
805        rc = set_start_bits(tcode, start_bits, caseless, utf8, cd);        rc = set_start_bits(tcode, start_bits, utf8, cd);
806        if (rc == SSB_FAIL) return SSB_FAIL;        if (rc == SSB_FAIL || rc == SSB_UNKNOWN) return rc;
807        if (rc == SSB_DONE) try_next = FALSE; else        if (rc == SSB_DONE) try_next = FALSE; else
808          {          {
809          do tcode += GET(tcode, 1); while (*tcode == OP_ALT);          do tcode += GET(tcode, 1); while (*tcode == OP_ALT);
# Line 659  do Line 826  do
826        case OP_KET:        case OP_KET:
827        case OP_KETRMAX:        case OP_KETRMAX:
828        case OP_KETRMIN:        case OP_KETRMIN:
829          case OP_KETRPOS:
830        return SSB_CONTINUE;        return SSB_CONTINUE;
831    
832        /* Skip over callout */        /* Skip over callout */
# Line 676  do Line 844  do
844        tcode += 1 + LINK_SIZE;        tcode += 1 + LINK_SIZE;
845        break;        break;
846    
       /* Skip over an option setting, changing the caseless flag */  
   
       case OP_OPT:  
       caseless = (tcode[1] & PCRE_CASELESS) != 0;  
       tcode += 2;  
       break;  
   
847        /* BRAZERO does the bracket, but carries on. */        /* BRAZERO does the bracket, but carries on. */
848    
849        case OP_BRAZERO:        case OP_BRAZERO:
850        case OP_BRAMINZERO:        case OP_BRAMINZERO:
851        if (set_start_bits(++tcode, start_bits, caseless, utf8, cd) == SSB_FAIL)        case OP_BRAPOSZERO:
852          return SSB_FAIL;        rc = set_start_bits(++tcode, start_bits, utf8, cd);
853          if (rc == SSB_FAIL || rc == SSB_UNKNOWN) return rc;
854  /* =========================================================================  /* =========================================================================
855        See the comment at the head of this function concerning the next line,        See the comment at the head of this function concerning the next line,
856        which was an old fudge for the benefit of OS/2.        which was an old fudge for the benefit of OS/2.
# Line 714  do Line 876  do
876        case OP_QUERY:        case OP_QUERY:
877        case OP_MINQUERY:        case OP_MINQUERY:
878        case OP_POSQUERY:        case OP_POSQUERY:
879        tcode = set_table_bit(start_bits, tcode + 1, caseless, cd, utf8);        tcode = set_table_bit(start_bits, tcode + 1, FALSE, cd, utf8);
880          break;
881    
882          case OP_STARI:
883          case OP_MINSTARI:
884          case OP_POSSTARI:
885          case OP_QUERYI:
886          case OP_MINQUERYI:
887          case OP_POSQUERYI:
888          tcode = set_table_bit(start_bits, tcode + 1, TRUE, cd, utf8);
889        break;        break;
890    
891        /* Single-char upto sets the bit and tries the next */        /* Single-char upto sets the bit and tries the next */
# Line 722  do Line 893  do
893        case OP_UPTO:        case OP_UPTO:
894        case OP_MINUPTO:        case OP_MINUPTO:
895        case OP_POSUPTO:        case OP_POSUPTO:
896        tcode = set_table_bit(start_bits, tcode + 3, caseless, cd, utf8);        tcode = set_table_bit(start_bits, tcode + 3, FALSE, cd, utf8);
897          break;
898    
899          case OP_UPTOI:
900          case OP_MINUPTOI:
901          case OP_POSUPTOI:
902          tcode = set_table_bit(start_bits, tcode + 3, TRUE, cd, utf8);
903        break;        break;
904    
905        /* At least one single char sets the bit and stops */        /* At least one single char sets the bit and stops */
906    
907        case OP_EXACT:       /* Fall through */        case OP_EXACT:
908        tcode += 2;        tcode += 2;
909          /* Fall through */
910        case OP_CHAR:        case OP_CHAR:
       case OP_CHARNC:  
911        case OP_PLUS:        case OP_PLUS:
912        case OP_MINPLUS:        case OP_MINPLUS:
913        case OP_POSPLUS:        case OP_POSPLUS:
914        (void)set_table_bit(start_bits, tcode + 1, caseless, cd, utf8);        (void)set_table_bit(start_bits, tcode + 1, FALSE, cd, utf8);
915          try_next = FALSE;
916          break;
917    
918          case OP_EXACTI:
919          tcode += 2;
920          /* Fall through */
921          case OP_CHARI:
922          case OP_PLUSI:
923          case OP_MINPLUSI:
924          case OP_POSPLUSI:
925          (void)set_table_bit(start_bits, tcode + 1, TRUE, cd, utf8);
926        try_next = FALSE;        try_next = FALSE;
927        break;        break;
928    
# Line 965  do Line 1152  do
1152            for (c = 0; c < 32; c++) start_bits[c] |= tcode[c];            for (c = 0; c < 32; c++) start_bits[c] |= tcode[c];
1153            }            }
1154    
1155          /* Advance past the bit map, and act on what follows */          /* Advance past the bit map, and act on what follows. For a zero
1156            minimum repeat, continue; otherwise stop processing. */
1157    
1158          tcode += 32;          tcode += 32;
1159          switch (*tcode)          switch (*tcode)
# Line 982  do Line 1170  do
1170            if (((tcode[1] << 8) + tcode[2]) == 0) tcode += 5;            if (((tcode[1] << 8) + tcode[2]) == 0) tcode += 5;
1171              else try_next = FALSE;              else try_next = FALSE;
1172            break;            break;
1173    
1174            default:            default:
1175            try_next = FALSE;            try_next = FALSE;
1176            break;            break;
# Line 1001  return yield; Line 1189  return yield;
1189    
1190    
1191    
1192    
1193    
1194  /*************************************************  /*************************************************
1195  *          Study a compiled expression           *  *          Study a compiled expression           *
1196  *************************************************/  *************************************************/
# Line 1025  pcre_study(const pcre *external_re, int Line 1215  pcre_study(const pcre *external_re, int
1215  {  {
1216  int min;  int min;
1217  BOOL bits_set = FALSE;  BOOL bits_set = FALSE;
1218    BOOL had_accept = FALSE;
1219  uschar start_bits[32];  uschar start_bits[32];
1220  pcre_extra *extra;  pcre_extra *extra;
1221  pcre_study_data *study;  pcre_study_data *study;
# Line 1057  seeking a list of starting bytes. */ Line 1248  seeking a list of starting bytes. */
1248  if ((re->options & PCRE_ANCHORED) == 0 &&  if ((re->options & PCRE_ANCHORED) == 0 &&
1249      (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) == 0)      (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) == 0)
1250    {    {
1251      int rc;
1252    
1253    /* Set the character tables in the block that is passed around */    /* Set the character tables in the block that is passed around */
1254    
1255    tables = re->tables;    tables = re->tables;
# Line 1072  if ((re->options & PCRE_ANCHORED) == 0 & Line 1265  if ((re->options & PCRE_ANCHORED) == 0 &
1265    /* See if we can find a fixed set of initial characters for the pattern. */    /* See if we can find a fixed set of initial characters for the pattern. */
1266    
1267    memset(start_bits, 0, 32 * sizeof(uschar));    memset(start_bits, 0, 32 * sizeof(uschar));
1268    bits_set = set_start_bits(code, start_bits,    rc = set_start_bits(code, start_bits, (re->options & PCRE_UTF8) != 0,
1269      (re->options & PCRE_CASELESS) != 0, (re->options & PCRE_UTF8) != 0,      &compile_block);
1270      &compile_block) == SSB_DONE;    bits_set = rc == SSB_DONE;
1271      if (rc == SSB_UNKNOWN) *errorptr = "internal error: opcode not recognized";
1272    }    }
1273    
1274  /* Find the minimum length of subject string. */  /* Find the minimum length of subject string. */
1275    
1276  min = find_minlength(code, code, re->options);  switch(min = find_minlength(code, code, re->options, &had_accept))
1277      {
1278      case -2: *errorptr = "internal error: missing capturing bracket"; break;
1279      case -3: *errorptr = "internal error: opcode not recognized"; break;
1280      default: break;
1281      }
1282    
1283  /* Return NULL if no optimization is possible. */  /* Return NULL if there's been an error or if no optimization is possible. */
1284    
1285  if (!bits_set && min < 0) return NULL;  if (*errorptr != NULL || (!bits_set && min < 0)) return NULL;
1286    
1287  /* 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
1288  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

Legend:
Removed from v.545  
changed lines
  Added in v.612

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12