Coverage Report

Created: 2025-08-29 06:48

/src/glib/glib/pcre/pcre_dfa_exec.c
Line
Count
Source (jump to first uncovered line)
1
/*************************************************
2
*      Perl-Compatible Regular Expressions       *
3
*************************************************/
4
5
/* PCRE is a library of functions to support regular expressions whose syntax
6
and semantics are as close as possible to those of the Perl 5 language (but see
7
below for why this module is different).
8
9
                       Written by Philip Hazel
10
           Copyright (c) 1997-2012 University of Cambridge
11
12
-----------------------------------------------------------------------------
13
Redistribution and use in source and binary forms, with or without
14
modification, are permitted provided that the following conditions are met:
15
16
    * Redistributions of source code must retain the above copyright notice,
17
      this list of conditions and the following disclaimer.
18
19
    * Redistributions in binary form must reproduce the above copyright
20
      notice, this list of conditions and the following disclaimer in the
21
      documentation and/or other materials provided with the distribution.
22
23
    * Neither the name of the University of Cambridge nor the names of its
24
      contributors may be used to endorse or promote products derived from
25
      this software without specific prior written permission.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
POSSIBILITY OF SUCH DAMAGE.
38
-----------------------------------------------------------------------------
39
*/
40
41
/* This module contains the external function pcre_dfa_exec(), which is an
42
alternative matching function that uses a sort of DFA algorithm (not a true
43
FSM). This is NOT Perl-compatible, but it has advantages in certain
44
applications. */
45
46
47
/* NOTE ABOUT PERFORMANCE: A user of this function sent some code that improved
48
the performance of his patterns greatly. I could not use it as it stood, as it
49
was not thread safe, and made assumptions about pattern sizes. Also, it caused
50
test 7 to loop, and test 9 to crash with a segfault.
51
52
The issue is the check for duplicate states, which is done by a simple linear
53
search up the state list. (Grep for "duplicate" below to find the code.) For
54
many patterns, there will never be many states active at one time, so a simple
55
linear search is fine. In patterns that have many active states, it might be a
56
bottleneck. The suggested code used an indexing scheme to remember which states
57
had previously been used for each character, and avoided the linear search when
58
it knew there was no chance of a duplicate. This was implemented when adding
59
states to the state lists.
60
61
I wrote some thread-safe, not-limited code to try something similar at the time
62
of checking for duplicates (instead of when adding states), using index vectors
63
on the stack. It did give a 13% improvement with one specially constructed
64
pattern for certain subject strings, but on other strings and on many of the
65
simpler patterns in the test suite it did worse. The major problem, I think,
66
was the extra time to initialize the index. This had to be done for each call
67
of internal_dfa_exec(). (The supplied patch used a static vector, initialized
68
only once - I suspect this was the cause of the problems with the tests.)
69
70
Overall, I concluded that the gains in some cases did not outweigh the losses
71
in others, so I abandoned this code. */
72
73
74
75
#include "config.h"
76
77
0
#define NLBLOCK md             /* Block containing newline information */
78
0
#define PSSTART start_subject  /* Field containing processed string start */
79
0
#define PSEND   end_subject    /* Field containing processed string end */
80
81
#include "pcre_internal.h"
82
83
84
/* For use to indent debugging output */
85
86
#define SP "                   "
87
88
89
/*************************************************
90
*      Code parameters and static tables         *
91
*************************************************/
92
93
/* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes
94
into others, under special conditions. A gap of 20 between the blocks should be
95
enough. The resulting opcodes don't have to be less than 256 because they are
96
never stored, so we push them well clear of the normal opcodes. */
97
98
0
#define OP_PROP_EXTRA       300
99
0
#define OP_EXTUNI_EXTRA     320
100
0
#define OP_ANYNL_EXTRA      340
101
0
#define OP_HSPACE_EXTRA     360
102
0
#define OP_VSPACE_EXTRA     380
103
104
105
/* This table identifies those opcodes that are followed immediately by a
106
character that is to be tested in some way. This makes it possible to
107
centralize the loading of these characters. In the case of Type * etc, the
108
"character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a
109
small value. Non-zero values in the table are the offsets from the opcode where
110
the character is to be found. ***NOTE*** If the start of this table is
111
modified, the three tables that follow must also be modified. */
112
113
static const pcre_uint8 coptable[] = {
114
  0,                             /* End                                    */
115
  0, 0, 0, 0, 0,                 /* \A, \G, \K, \B, \b                     */
116
  0, 0, 0, 0, 0, 0,              /* \D, \d, \S, \s, \W, \w                 */
117
  0, 0, 0,                       /* Any, AllAny, Anybyte                   */
118
  0, 0,                          /* \P, \p                                 */
119
  0, 0, 0, 0, 0,                 /* \R, \H, \h, \V, \v                     */
120
  0,                             /* \X                                     */
121
  0, 0, 0, 0, 0, 0,              /* \Z, \z, ^, ^M, $, $M                   */
122
  1,                             /* Char                                   */
123
  1,                             /* Chari                                  */
124
  1,                             /* not                                    */
125
  1,                             /* noti                                   */
126
  /* Positive single-char repeats                                          */
127
  1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
128
  1+IMM2_SIZE, 1+IMM2_SIZE,      /* upto, minupto                          */
129
  1+IMM2_SIZE,                   /* exact                                  */
130
  1, 1, 1, 1+IMM2_SIZE,          /* *+, ++, ?+, upto+                      */
131
  1, 1, 1, 1, 1, 1,              /* *I, *?I, +I, +?I, ?I, ??I              */
132
  1+IMM2_SIZE, 1+IMM2_SIZE,      /* upto I, minupto I                      */
133
  1+IMM2_SIZE,                   /* exact I                                */
134
  1, 1, 1, 1+IMM2_SIZE,          /* *+I, ++I, ?+I, upto+I                  */
135
  /* Negative single-char repeats - only for chars < 256                   */
136
  1, 1, 1, 1, 1, 1,              /* NOT *, *?, +, +?, ?, ??                */
137
  1+IMM2_SIZE, 1+IMM2_SIZE,      /* NOT upto, minupto                      */
138
  1+IMM2_SIZE,                   /* NOT exact                              */
139
  1, 1, 1, 1+IMM2_SIZE,          /* NOT *+, ++, ?+, upto+                  */
140
  1, 1, 1, 1, 1, 1,              /* NOT *I, *?I, +I, +?I, ?I, ??I          */
141
  1+IMM2_SIZE, 1+IMM2_SIZE,      /* NOT upto I, minupto I                  */
142
  1+IMM2_SIZE,                   /* NOT exact I                            */
143
  1, 1, 1, 1+IMM2_SIZE,          /* NOT *+I, ++I, ?+I, upto+I              */
144
  /* Positive type repeats                                                 */
145
  1, 1, 1, 1, 1, 1,              /* Type *, *?, +, +?, ?, ??               */
146
  1+IMM2_SIZE, 1+IMM2_SIZE,      /* Type upto, minupto                     */
147
  1+IMM2_SIZE,                   /* Type exact                             */
148
  1, 1, 1, 1+IMM2_SIZE,          /* Type *+, ++, ?+, upto+                 */
149
  /* Character class & ref repeats                                         */
150
  0, 0, 0, 0, 0, 0,              /* *, *?, +, +?, ?, ??                    */
151
  0, 0,                          /* CRRANGE, CRMINRANGE                    */
152
  0,                             /* CLASS                                  */
153
  0,                             /* NCLASS                                 */
154
  0,                             /* XCLASS - variable length               */
155
  0,                             /* REF                                    */
156
  0,                             /* REFI                                   */
157
  0,                             /* RECURSE                                */
158
  0,                             /* CALLOUT                                */
159
  0,                             /* Alt                                    */
160
  0,                             /* Ket                                    */
161
  0,                             /* KetRmax                                */
162
  0,                             /* KetRmin                                */
163
  0,                             /* KetRpos                                */
164
  0,                             /* Reverse                                */
165
  0,                             /* Assert                                 */
166
  0,                             /* Assert not                             */
167
  0,                             /* Assert behind                          */
168
  0,                             /* Assert behind not                      */
169
  0, 0,                          /* ONCE, ONCE_NC                          */
170
  0, 0, 0, 0, 0,                 /* BRA, BRAPOS, CBRA, CBRAPOS, COND       */
171
  0, 0, 0, 0, 0,                 /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND  */
172
  0, 0,                          /* CREF, NCREF                            */
173
  0, 0,                          /* RREF, NRREF                            */
174
  0,                             /* DEF                                    */
175
  0, 0, 0,                       /* BRAZERO, BRAMINZERO, BRAPOSZERO        */
176
  0, 0, 0,                       /* MARK, PRUNE, PRUNE_ARG                 */
177
  0, 0, 0, 0,                    /* SKIP, SKIP_ARG, THEN, THEN_ARG         */
178
  0, 0, 0, 0,                    /* COMMIT, FAIL, ACCEPT, ASSERT_ACCEPT    */
179
  0, 0                           /* CLOSE, SKIPZERO  */
180
};
181
182
/* This table identifies those opcodes that inspect a character. It is used to
183
remember the fact that a character could have been inspected when the end of
184
the subject is reached. ***NOTE*** If the start of this table is modified, the
185
two tables that follow must also be modified. */
186
187
static const pcre_uint8 poptable[] = {
188
  0,                             /* End                                    */
189
  0, 0, 0, 1, 1,                 /* \A, \G, \K, \B, \b                     */
190
  1, 1, 1, 1, 1, 1,              /* \D, \d, \S, \s, \W, \w                 */
191
  1, 1, 1,                       /* Any, AllAny, Anybyte                   */
192
  1, 1,                          /* \P, \p                                 */
193
  1, 1, 1, 1, 1,                 /* \R, \H, \h, \V, \v                     */
194
  1,                             /* \X                                     */
195
  0, 0, 0, 0, 0, 0,              /* \Z, \z, ^, ^M, $, $M                   */
196
  1,                             /* Char                                   */
197
  1,                             /* Chari                                  */
198
  1,                             /* not                                    */
199
  1,                             /* noti                                   */
200
  /* Positive single-char repeats                                          */
201
  1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
202
  1, 1, 1,                       /* upto, minupto, exact                   */
203
  1, 1, 1, 1,                    /* *+, ++, ?+, upto+                      */
204
  1, 1, 1, 1, 1, 1,              /* *I, *?I, +I, +?I, ?I, ??I              */
205
  1, 1, 1,                       /* upto I, minupto I, exact I             */
206
  1, 1, 1, 1,                    /* *+I, ++I, ?+I, upto+I                  */
207
  /* Negative single-char repeats - only for chars < 256                   */
208
  1, 1, 1, 1, 1, 1,              /* NOT *, *?, +, +?, ?, ??                */
209
  1, 1, 1,                       /* NOT upto, minupto, exact               */
210
  1, 1, 1, 1,                    /* NOT *+, ++, ?+, upto+                  */
211
  1, 1, 1, 1, 1, 1,              /* NOT *I, *?I, +I, +?I, ?I, ??I          */
212
  1, 1, 1,                       /* NOT upto I, minupto I, exact I         */
213
  1, 1, 1, 1,                    /* NOT *+I, ++I, ?+I, upto+I              */
214
  /* Positive type repeats                                                 */
215
  1, 1, 1, 1, 1, 1,              /* Type *, *?, +, +?, ?, ??               */
216
  1, 1, 1,                       /* Type upto, minupto, exact              */
217
  1, 1, 1, 1,                    /* Type *+, ++, ?+, upto+                 */
218
  /* Character class & ref repeats                                         */
219
  1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */
220
  1, 1,                          /* CRRANGE, CRMINRANGE                    */
221
  1,                             /* CLASS                                  */
222
  1,                             /* NCLASS                                 */
223
  1,                             /* XCLASS - variable length               */
224
  0,                             /* REF                                    */
225
  0,                             /* REFI                                   */
226
  0,                             /* RECURSE                                */
227
  0,                             /* CALLOUT                                */
228
  0,                             /* Alt                                    */
229
  0,                             /* Ket                                    */
230
  0,                             /* KetRmax                                */
231
  0,                             /* KetRmin                                */
232
  0,                             /* KetRpos                                */
233
  0,                             /* Reverse                                */
234
  0,                             /* Assert                                 */
235
  0,                             /* Assert not                             */
236
  0,                             /* Assert behind                          */
237
  0,                             /* Assert behind not                      */
238
  0, 0,                          /* ONCE, ONCE_NC                          */
239
  0, 0, 0, 0, 0,                 /* BRA, BRAPOS, CBRA, CBRAPOS, COND       */
240
  0, 0, 0, 0, 0,                 /* SBRA, SBRAPOS, SCBRA, SCBRAPOS, SCOND  */
241
  0, 0,                          /* CREF, NCREF                            */
242
  0, 0,                          /* RREF, NRREF                            */
243
  0,                             /* DEF                                    */
244
  0, 0, 0,                       /* BRAZERO, BRAMINZERO, BRAPOSZERO        */
245
  0, 0, 0,                       /* MARK, PRUNE, PRUNE_ARG                 */
246
  0, 0, 0, 0,                    /* SKIP, SKIP_ARG, THEN, THEN_ARG         */
247
  0, 0, 0, 0,                    /* COMMIT, FAIL, ACCEPT, ASSERT_ACCEPT    */
248
  0, 0                           /* CLOSE, SKIPZERO                        */
249
};
250
251
/* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W,
252
and \w */
253
254
static const pcre_uint8 toptable1[] = {
255
  0, 0, 0, 0, 0, 0,
256
  ctype_digit, ctype_digit,
257
  ctype_space, ctype_space,
258
  ctype_word,  ctype_word,
259
  0, 0                            /* OP_ANY, OP_ALLANY */
260
};
261
262
static const pcre_uint8 toptable2[] = {
263
  0, 0, 0, 0, 0, 0,
264
  ctype_digit, 0,
265
  ctype_space, 0,
266
  ctype_word,  0,
267
  1, 1                            /* OP_ANY, OP_ALLANY */
268
};
269
270
271
/* Structure for holding data about a particular state, which is in effect the
272
current data for an active path through the match tree. It must consist
273
entirely of ints because the working vector we are passed, and which we put
274
these structures in, is a vector of ints. */
275
276
typedef struct stateblock {
277
  int offset;                     /* Offset to opcode */
278
  int count;                      /* Count for repeats */
279
  int data;                       /* Some use extra data */
280
} stateblock;
281
282
0
#define INTS_PER_STATEBLOCK  (int)(sizeof(stateblock)/sizeof(int))
283
284
285
#ifdef PCRE_DEBUG
286
/*************************************************
287
*             Print character string             *
288
*************************************************/
289
290
/* Character string printing function for debugging.
291
292
Arguments:
293
  p            points to string
294
  length       number of bytes
295
  f            where to print
296
297
Returns:       nothing
298
*/
299
300
static void
301
pchars(const pcre_uchar *p, int length, FILE *f)
302
{
303
int c;
304
while (length-- > 0)
305
  {
306
  if (isprint(c = *(p++)))
307
    fprintf(f, "%c", c);
308
  else
309
    fprintf(f, "\\x%02x", c);
310
  }
311
}
312
#endif
313
314
315
316
/*************************************************
317
*    Execute a Regular Expression - DFA engine   *
318
*************************************************/
319
320
/* This internal function applies a compiled pattern to a subject string,
321
starting at a given point, using a DFA engine. This function is called from the
322
external one, possibly multiple times if the pattern is not anchored. The
323
function calls itself recursively for some kinds of subpattern.
324
325
Arguments:
326
  md                the match_data block with fixed information
327
  this_start_code   the opening bracket of this subexpression's code
328
  current_subject   where we currently are in the subject string
329
  start_offset      start offset in the subject string
330
  offsets           vector to contain the matching string offsets
331
  offsetcount       size of same
332
  workspace         vector of workspace
333
  wscount           size of same
334
  rlevel            function call recursion level
335
336
Returns:            > 0 => number of match offset pairs placed in offsets
337
                    = 0 => offsets overflowed; longest matches are present
338
                     -1 => failed to match
339
                   < -1 => some kind of unexpected problem
340
341
The following macros are used for adding states to the two state vectors (one
342
for the current character, one for the following character). */
343
344
#define ADD_ACTIVE(x,y) \
345
0
  if (active_count++ < wscount) \
346
0
    { \
347
0
    next_active_state->offset = (x); \
348
0
    next_active_state->count  = (y); \
349
0
    next_active_state++; \
350
0
    DPRINTF(("%.*sADD_ACTIVE(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
351
0
    } \
352
0
  else return PCRE_ERROR_DFA_WSSIZE
353
354
#define ADD_ACTIVE_DATA(x,y,z) \
355
  if (active_count++ < wscount) \
356
    { \
357
    next_active_state->offset = (x); \
358
    next_active_state->count  = (y); \
359
    next_active_state->data   = (z); \
360
    next_active_state++; \
361
    DPRINTF(("%.*sADD_ACTIVE_DATA(%d,%d,%d)\n", rlevel*2-2, SP, (x), (y), (z))); \
362
    } \
363
  else return PCRE_ERROR_DFA_WSSIZE
364
365
#define ADD_NEW(x,y) \
366
0
  if (new_count++ < wscount) \
367
0
    { \
368
0
    next_new_state->offset = (x); \
369
0
    next_new_state->count  = (y); \
370
0
    next_new_state++; \
371
0
    DPRINTF(("%.*sADD_NEW(%d,%d)\n", rlevel*2-2, SP, (x), (y))); \
372
0
    } \
373
0
  else return PCRE_ERROR_DFA_WSSIZE
374
375
#define ADD_NEW_DATA(x,y,z) \
376
0
  if (new_count++ < wscount) \
377
0
    { \
378
0
    next_new_state->offset = (x); \
379
0
    next_new_state->count  = (y); \
380
0
    next_new_state->data   = (z); \
381
0
    next_new_state++; \
382
0
    DPRINTF(("%.*sADD_NEW_DATA(%d,%d,%d) line %d\n", rlevel*2-2, SP, \
383
0
      (x), (y), (z), __LINE__)); \
384
0
    } \
385
0
  else return PCRE_ERROR_DFA_WSSIZE
386
387
/* And now, here is the code */
388
389
static int
390
internal_dfa_exec(
391
  dfa_match_data *md,
392
  const pcre_uchar *this_start_code,
393
  const pcre_uchar *current_subject,
394
  int start_offset,
395
  int *offsets,
396
  int offsetcount,
397
  int *workspace,
398
  int wscount,
399
  int  rlevel)
400
0
{
401
0
stateblock *active_states, *new_states, *temp_states;
402
0
stateblock *next_active_state, *next_new_state;
403
404
0
const pcre_uint8 *ctypes, *lcc, *fcc;
405
0
const pcre_uchar *ptr;
406
0
const pcre_uchar *end_code, *first_op;
407
408
0
dfa_recursion_info new_recursive;
409
410
0
int active_count, new_count, match_count;
411
412
/* Some fields in the md block are frequently referenced, so we load them into
413
independent variables in the hope that this will perform better. */
414
415
0
const pcre_uchar *start_subject = md->start_subject;
416
0
const pcre_uchar *end_subject = md->end_subject;
417
0
const pcre_uchar *start_code = md->start_code;
418
419
0
#ifdef SUPPORT_UTF
420
0
BOOL utf = (md->poptions & PCRE_UTF8) != 0;
421
#else
422
BOOL utf = FALSE;
423
#endif
424
425
0
BOOL reset_could_continue = FALSE;
426
427
0
rlevel++;
428
0
offsetcount &= (-2);
429
430
0
wscount -= 2;
431
0
wscount = (wscount - (wscount % (INTS_PER_STATEBLOCK * 2))) /
432
0
          (2 * INTS_PER_STATEBLOCK);
433
434
0
DPRINTF(("\n%.*s---------------------\n"
435
0
  "%.*sCall to internal_dfa_exec f=%d\n",
436
0
  rlevel*2-2, SP, rlevel*2-2, SP, rlevel));
437
438
0
ctypes = md->tables + ctypes_offset;
439
0
lcc = md->tables + lcc_offset;
440
0
fcc = md->tables + fcc_offset;
441
442
0
match_count = PCRE_ERROR_NOMATCH;   /* A negative number */
443
444
0
active_states = (stateblock *)(workspace + 2);
445
0
next_new_state = new_states = active_states + wscount;
446
0
new_count = 0;
447
448
0
first_op = this_start_code + 1 + LINK_SIZE +
449
0
  ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA ||
450
0
    *this_start_code == OP_CBRAPOS || *this_start_code == OP_SCBRAPOS)
451
0
    ? IMM2_SIZE:0);
452
453
/* The first thing in any (sub) pattern is a bracket of some sort. Push all
454
the alternative states onto the list, and find out where the end is. This
455
makes is possible to use this function recursively, when we want to stop at a
456
matching internal ket rather than at the end.
457
458
If the first opcode in the first alternative is OP_REVERSE, we are dealing with
459
a backward assertion. In that case, we have to find out the maximum amount to
460
move back, and set up each alternative appropriately. */
461
462
0
if (*first_op == OP_REVERSE)
463
0
  {
464
0
  int max_back = 0;
465
0
  int gone_back;
466
467
0
  end_code = this_start_code;
468
0
  do
469
0
    {
470
0
    int back = GET(end_code, 2+LINK_SIZE);
471
0
    if (back > max_back) max_back = back;
472
0
    end_code += GET(end_code, 1);
473
0
    }
474
0
  while (*end_code == OP_ALT);
475
476
  /* If we can't go back the amount required for the longest lookbehind
477
  pattern, go back as far as we can; some alternatives may still be viable. */
478
479
0
#ifdef SUPPORT_UTF
480
  /* In character mode we have to step back character by character */
481
482
0
  if (utf)
483
0
    {
484
0
    for (gone_back = 0; gone_back < max_back; gone_back++)
485
0
      {
486
0
      if (current_subject <= start_subject) break;
487
0
      current_subject--;
488
0
      ACROSSCHAR(current_subject > start_subject, *current_subject, current_subject--);
489
0
      }
490
0
    }
491
0
  else
492
0
#endif
493
494
  /* In byte-mode we can do this quickly. */
495
496
0
    {
497
0
    gone_back = (current_subject - max_back < start_subject)?
498
0
      (int)(current_subject - start_subject) : max_back;
499
0
    current_subject -= gone_back;
500
0
    }
501
502
  /* Save the earliest consulted character */
503
504
0
  if (current_subject < md->start_used_ptr)
505
0
    md->start_used_ptr = current_subject;
506
507
  /* Now we can process the individual branches. */
508
509
0
  end_code = this_start_code;
510
0
  do
511
0
    {
512
0
    int back = GET(end_code, 2+LINK_SIZE);
513
0
    if (back <= gone_back)
514
0
      {
515
0
      int bstate = (int)(end_code - start_code + 2 + 2*LINK_SIZE);
516
0
      ADD_NEW_DATA(-bstate, 0, gone_back - back);
517
0
      }
518
0
    end_code += GET(end_code, 1);
519
0
    }
520
0
  while (*end_code == OP_ALT);
521
0
 }
522
523
/* This is the code for a "normal" subpattern (not a backward assertion). The
524
start of a whole pattern is always one of these. If we are at the top level,
525
we may be asked to restart matching from the same point that we reached for a
526
previous partial match. We still have to scan through the top-level branches to
527
find the end state. */
528
529
0
else
530
0
  {
531
0
  end_code = this_start_code;
532
533
  /* Restarting */
534
535
0
  if (rlevel == 1 && (md->moptions & PCRE_DFA_RESTART) != 0)
536
0
    {
537
0
    do { end_code += GET(end_code, 1); } while (*end_code == OP_ALT);
538
0
    new_count = workspace[1];
539
0
    if (!workspace[0])
540
0
      memcpy(new_states, active_states, new_count * sizeof(stateblock));
541
0
    }
542
543
  /* Not restarting */
544
545
0
  else
546
0
    {
547
0
    int length = 1 + LINK_SIZE +
548
0
      ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA ||
549
0
        *this_start_code == OP_CBRAPOS || *this_start_code == OP_SCBRAPOS)
550
0
        ? IMM2_SIZE:0);
551
0
    do
552
0
      {
553
0
      ADD_NEW((int)(end_code - start_code + length), 0);
554
0
      end_code += GET(end_code, 1);
555
0
      length = 1 + LINK_SIZE;
556
0
      }
557
0
    while (*end_code == OP_ALT);
558
0
    }
559
0
  }
560
561
0
workspace[0] = 0;    /* Bit indicating which vector is current */
562
563
0
DPRINTF(("%.*sEnd state = %d\n", rlevel*2-2, SP, (int)(end_code - start_code)));
564
565
/* Loop for scanning the subject */
566
567
0
ptr = current_subject;
568
0
for (;;)
569
0
  {
570
0
  int i, j;
571
0
  int clen, dlen;
572
0
  unsigned int c, d;
573
0
  int forced_fail = 0;
574
0
  BOOL partial_newline = FALSE;
575
0
  BOOL could_continue = reset_could_continue;
576
0
  reset_could_continue = FALSE;
577
578
  /* Make the new state list into the active state list and empty the
579
  new state list. */
580
581
0
  temp_states = active_states;
582
0
  active_states = new_states;
583
0
  new_states = temp_states;
584
0
  active_count = new_count;
585
0
  new_count = 0;
586
587
0
  workspace[0] ^= 1;              /* Remember for the restarting feature */
588
0
  workspace[1] = active_count;
589
590
#ifdef PCRE_DEBUG
591
  printf("%.*sNext character: rest of subject = \"", rlevel*2-2, SP);
592
  pchars(ptr, STRLEN_UC(ptr), stdout);
593
  printf("\"\n");
594
595
  printf("%.*sActive states: ", rlevel*2-2, SP);
596
  for (i = 0; i < active_count; i++)
597
    printf("%d/%d ", active_states[i].offset, active_states[i].count);
598
  printf("\n");
599
#endif
600
601
  /* Set the pointers for adding new states */
602
603
0
  next_active_state = active_states + active_count;
604
0
  next_new_state = new_states;
605
606
  /* Load the current character from the subject outside the loop, as many
607
  different states may want to look at it, and we assume that at least one
608
  will. */
609
610
0
  if (ptr < end_subject)
611
0
    {
612
0
    clen = 1;        /* Number of data items in the character */
613
0
#ifdef SUPPORT_UTF
614
0
    if (utf) { GETCHARLEN(c, ptr, clen); } else
615
0
#endif  /* SUPPORT_UTF */
616
0
    c = *ptr;
617
0
    }
618
0
  else
619
0
    {
620
0
    clen = 0;        /* This indicates the end of the subject */
621
0
    c = NOTACHAR;    /* This value should never actually be used */
622
0
    }
623
624
  /* Scan up the active states and act on each one. The result of an action
625
  may be to add more states to the currently active list (e.g. on hitting a
626
  parenthesis) or it may be to put states on the new list, for considering
627
  when we move the character pointer on. */
628
629
0
  for (i = 0; i < active_count; i++)
630
0
    {
631
0
    stateblock *current_state = active_states + i;
632
0
    BOOL caseless = FALSE;
633
0
    const pcre_uchar *code;
634
0
    int state_offset = current_state->offset;
635
0
    int count, codevalue, rrc;
636
637
#ifdef PCRE_DEBUG
638
    printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset);
639
    if (clen == 0) printf("EOL\n");
640
      else if (c > 32 && c < 127) printf("'%c'\n", c);
641
        else printf("0x%02x\n", c);
642
#endif
643
644
    /* A negative offset is a special case meaning "hold off going to this
645
    (negated) state until the number of characters in the data field have
646
    been skipped". If the could_continue flag was passed over from a previous
647
    state, arrange for it to passed on. */
648
649
0
    if (state_offset < 0)
650
0
      {
651
0
      if (current_state->data > 0)
652
0
        {
653
0
        DPRINTF(("%.*sSkipping this character\n", rlevel*2-2, SP));
654
0
        ADD_NEW_DATA(state_offset, current_state->count,
655
0
          current_state->data - 1);
656
0
        if (could_continue) reset_could_continue = TRUE;
657
0
        continue;
658
0
        }
659
0
      else
660
0
        {
661
0
        current_state->offset = state_offset = -state_offset;
662
0
        }
663
0
      }
664
665
    /* Check for a duplicate state with the same count, and skip if found.
666
    See the note at the head of this module about the possibility of improving
667
    performance here. */
668
669
0
    for (j = 0; j < i; j++)
670
0
      {
671
0
      if (active_states[j].offset == state_offset &&
672
0
          active_states[j].count == current_state->count)
673
0
        {
674
0
        DPRINTF(("%.*sDuplicate state: skipped\n", rlevel*2-2, SP));
675
0
        goto NEXT_ACTIVE_STATE;
676
0
        }
677
0
      }
678
679
    /* The state offset is the offset to the opcode */
680
681
0
    code = start_code + state_offset;
682
0
    codevalue = *code;
683
684
    /* If this opcode inspects a character, but we are at the end of the
685
    subject, remember the fact for use when testing for a partial match. */
686
687
0
    if (clen == 0 && poptable[codevalue] != 0)
688
0
      could_continue = TRUE;
689
690
    /* If this opcode is followed by an inline character, load it. It is
691
    tempting to test for the presence of a subject character here, but that
692
    is wrong, because sometimes zero repetitions of the subject are
693
    permitted.
694
695
    We also use this mechanism for opcodes such as OP_TYPEPLUS that take an
696
    argument that is not a data character - but is always one byte long because
697
    the values are small. We have to take special action to deal with  \P, \p,
698
    \H, \h, \V, \v and \X in this case. To keep the other cases fast, convert
699
    these ones to new opcodes. */
700
701
0
    if (coptable[codevalue] > 0)
702
0
      {
703
0
      dlen = 1;
704
0
#ifdef SUPPORT_UTF
705
0
      if (utf) { GETCHARLEN(d, (code + coptable[codevalue]), dlen); } else
706
0
#endif  /* SUPPORT_UTF */
707
0
      d = code[coptable[codevalue]];
708
0
      if (codevalue >= OP_TYPESTAR)
709
0
        {
710
0
        switch(d)
711
0
          {
712
0
          case OP_ANYBYTE: return PCRE_ERROR_DFA_UITEM;
713
0
          case OP_NOTPROP:
714
0
          case OP_PROP: codevalue += OP_PROP_EXTRA; break;
715
0
          case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break;
716
0
          case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break;
717
0
          case OP_NOT_HSPACE:
718
0
          case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break;
719
0
          case OP_NOT_VSPACE:
720
0
          case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break;
721
0
          default: break;
722
0
          }
723
0
        }
724
0
      }
725
0
    else
726
0
      {
727
0
      dlen = 0;         /* Not strictly necessary, but compilers moan */
728
0
      d = NOTACHAR;     /* if these variables are not set. */
729
0
      }
730
731
732
    /* Now process the individual opcodes */
733
734
0
    switch (codevalue)
735
0
      {
736
/* ========================================================================== */
737
      /* These cases are never obeyed. This is a fudge that causes a compile-
738
      time error if the vectors coptable or poptable, which are indexed by
739
      opcode, are not the correct length. It seems to be the only way to do
740
      such a check at compile time, as the sizeof() operator does not work
741
      in the C preprocessor. */
742
743
0
      case OP_TABLE_LENGTH:
744
0
      case OP_TABLE_LENGTH +
745
0
        ((sizeof(coptable) == OP_TABLE_LENGTH) &&
746
0
         (sizeof(poptable) == OP_TABLE_LENGTH)):
747
0
      break;
748
749
/* ========================================================================== */
750
      /* Reached a closing bracket. If not at the end of the pattern, carry
751
      on with the next opcode. For repeating opcodes, also add the repeat
752
      state. Note that KETRPOS will always be encountered at the end of the
753
      subpattern, because the possessive subpattern repeats are always handled
754
      using recursive calls. Thus, it never adds any new states.
755
756
      At the end of the (sub)pattern, unless we have an empty string and
757
      PCRE_NOTEMPTY is set, or PCRE_NOTEMPTY_ATSTART is set and we are at the
758
      start of the subject, save the match data, shifting up all previous
759
      matches so we always have the longest first. */
760
761
0
      case OP_KET:
762
0
      case OP_KETRMIN:
763
0
      case OP_KETRMAX:
764
0
      case OP_KETRPOS:
765
0
      if (code != end_code)
766
0
        {
767
0
        ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);
768
0
        if (codevalue != OP_KET)
769
0
          {
770
0
          ADD_ACTIVE(state_offset - GET(code, 1), 0);
771
0
          }
772
0
        }
773
0
      else
774
0
        {
775
0
        if (ptr > current_subject ||
776
0
            ((md->moptions & PCRE_NOTEMPTY) == 0 &&
777
0
              ((md->moptions & PCRE_NOTEMPTY_ATSTART) == 0 ||
778
0
                current_subject > start_subject + md->start_offset)))
779
0
          {
780
0
          if (match_count < 0) match_count = (offsetcount >= 2)? 1 : 0;
781
0
            else if (match_count > 0 && ++match_count * 2 > offsetcount)
782
0
              match_count = 0;
783
0
          count = ((match_count == 0)? offsetcount : match_count * 2) - 2;
784
0
          if (count > 0) memmove(offsets + 2, offsets, count * sizeof(int));
785
0
          if (offsetcount >= 2)
786
0
            {
787
0
            offsets[0] = (int)(current_subject - start_subject);
788
0
            offsets[1] = (int)(ptr - start_subject);
789
0
            DPRINTF(("%.*sSet matched string = \"%.*s\"\n", rlevel*2-2, SP,
790
0
              offsets[1] - offsets[0], (char *)current_subject));
791
0
            }
792
0
          if ((md->moptions & PCRE_DFA_SHORTEST) != 0)
793
0
            {
794
0
            DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"
795
0
              "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel,
796
0
              match_count, rlevel*2-2, SP));
797
0
            return match_count;
798
0
            }
799
0
          }
800
0
        }
801
0
      break;
802
803
/* ========================================================================== */
804
      /* These opcodes add to the current list of states without looking
805
      at the current character. */
806
807
      /*-----------------------------------------------------------------*/
808
0
      case OP_ALT:
809
0
      do { code += GET(code, 1); } while (*code == OP_ALT);
810
0
      ADD_ACTIVE((int)(code - start_code), 0);
811
0
      break;
812
813
      /*-----------------------------------------------------------------*/
814
0
      case OP_BRA:
815
0
      case OP_SBRA:
816
0
      do
817
0
        {
818
0
        ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
819
0
        code += GET(code, 1);
820
0
        }
821
0
      while (*code == OP_ALT);
822
0
      break;
823
824
      /*-----------------------------------------------------------------*/
825
0
      case OP_CBRA:
826
0
      case OP_SCBRA:
827
0
      ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE + IMM2_SIZE),  0);
828
0
      code += GET(code, 1);
829
0
      while (*code == OP_ALT)
830
0
        {
831
0
        ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE),  0);
832
0
        code += GET(code, 1);
833
0
        }
834
0
      break;
835
836
      /*-----------------------------------------------------------------*/
837
0
      case OP_BRAZERO:
838
0
      case OP_BRAMINZERO:
839
0
      ADD_ACTIVE(state_offset + 1, 0);
840
0
      code += 1 + GET(code, 2);
841
0
      while (*code == OP_ALT) code += GET(code, 1);
842
0
      ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
843
0
      break;
844
845
      /*-----------------------------------------------------------------*/
846
0
      case OP_SKIPZERO:
847
0
      code += 1 + GET(code, 2);
848
0
      while (*code == OP_ALT) code += GET(code, 1);
849
0
      ADD_ACTIVE((int)(code - start_code + 1 + LINK_SIZE), 0);
850
0
      break;
851
852
      /*-----------------------------------------------------------------*/
853
0
      case OP_CIRC:
854
0
      if (ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0)
855
0
        { ADD_ACTIVE(state_offset + 1, 0); }
856
0
      break;
857
858
      /*-----------------------------------------------------------------*/
859
0
      case OP_CIRCM:
860
0
      if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) ||
861
0
          (ptr != end_subject && WAS_NEWLINE(ptr)))
862
0
        { ADD_ACTIVE(state_offset + 1, 0); }
863
0
      break;
864
865
      /*-----------------------------------------------------------------*/
866
0
      case OP_EOD:
867
0
      if (ptr >= end_subject)
868
0
        {
869
0
        if ((md->moptions & PCRE_PARTIAL_HARD) != 0)
870
0
          could_continue = TRUE;
871
0
        else { ADD_ACTIVE(state_offset + 1, 0); }
872
0
        }
873
0
      break;
874
875
      /*-----------------------------------------------------------------*/
876
0
      case OP_SOD:
877
0
      if (ptr == start_subject) { ADD_ACTIVE(state_offset + 1, 0); }
878
0
      break;
879
880
      /*-----------------------------------------------------------------*/
881
0
      case OP_SOM:
882
0
      if (ptr == start_subject + start_offset) { ADD_ACTIVE(state_offset + 1, 0); }
883
0
      break;
884
885
886
/* ========================================================================== */
887
      /* These opcodes inspect the next subject character, and sometimes
888
      the previous one as well, but do not have an argument. The variable
889
      clen contains the length of the current character and is zero if we are
890
      at the end of the subject. */
891
892
      /*-----------------------------------------------------------------*/
893
0
      case OP_ANY:
894
0
      if (clen > 0 && !IS_NEWLINE(ptr))
895
0
        {
896
0
        if (ptr + 1 >= md->end_subject &&
897
0
            (md->moptions & (PCRE_PARTIAL_HARD)) != 0 &&
898
0
            NLBLOCK->nltype == NLTYPE_FIXED &&
899
0
            NLBLOCK->nllen == 2 &&
900
0
            c == NLBLOCK->nl[0])
901
0
          {
902
0
          could_continue = partial_newline = TRUE;
903
0
          }
904
0
        else
905
0
          {
906
0
          ADD_NEW(state_offset + 1, 0);
907
0
          }
908
0
        }
909
0
      break;
910
911
      /*-----------------------------------------------------------------*/
912
0
      case OP_ALLANY:
913
0
      if (clen > 0)
914
0
        { ADD_NEW(state_offset + 1, 0); }
915
0
      break;
916
917
      /*-----------------------------------------------------------------*/
918
0
      case OP_EODN:
919
0
      if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
920
0
        could_continue = TRUE;
921
0
      else if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen))
922
0
        { ADD_ACTIVE(state_offset + 1, 0); }
923
0
      break;
924
925
      /*-----------------------------------------------------------------*/
926
0
      case OP_DOLL:
927
0
      if ((md->moptions & PCRE_NOTEOL) == 0)
928
0
        {
929
0
        if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
930
0
          could_continue = TRUE;
931
0
        else if (clen == 0 ||
932
0
            ((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr) &&
933
0
               (ptr == end_subject - md->nllen)
934
0
            ))
935
0
          { ADD_ACTIVE(state_offset + 1, 0); }
936
0
        else if (ptr + 1 >= md->end_subject &&
937
0
                 (md->moptions & (PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT)) != 0 &&
938
0
                 NLBLOCK->nltype == NLTYPE_FIXED &&
939
0
                 NLBLOCK->nllen == 2 &&
940
0
                 c == NLBLOCK->nl[0])
941
0
          {
942
0
          if ((md->moptions & PCRE_PARTIAL_HARD) != 0)
943
0
            {
944
0
            reset_could_continue = TRUE;
945
0
            ADD_NEW_DATA(-(state_offset + 1), 0, 1);
946
0
            }
947
0
          else could_continue = partial_newline = TRUE;
948
0
          }
949
0
        }
950
0
      break;
951
952
      /*-----------------------------------------------------------------*/
953
0
      case OP_DOLLM:
954
0
      if ((md->moptions & PCRE_NOTEOL) == 0)
955
0
        {
956
0
        if (clen == 0 && (md->moptions & PCRE_PARTIAL_HARD) != 0)
957
0
          could_continue = TRUE;
958
0
        else if (clen == 0 ||
959
0
            ((md->poptions & PCRE_DOLLAR_ENDONLY) == 0 && IS_NEWLINE(ptr)))
960
0
          { ADD_ACTIVE(state_offset + 1, 0); }
961
0
        else if (ptr + 1 >= md->end_subject &&
962
0
                 (md->moptions & (PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT)) != 0 &&
963
0
                 NLBLOCK->nltype == NLTYPE_FIXED &&
964
0
                 NLBLOCK->nllen == 2 &&
965
0
                 c == NLBLOCK->nl[0])
966
0
          {
967
0
          if ((md->moptions & PCRE_PARTIAL_HARD) != 0)
968
0
            {
969
0
            reset_could_continue = TRUE;
970
0
            ADD_NEW_DATA(-(state_offset + 1), 0, 1);
971
0
            }
972
0
          else could_continue = partial_newline = TRUE;
973
0
          }
974
0
        }
975
0
      else if (IS_NEWLINE(ptr))
976
0
        { ADD_ACTIVE(state_offset + 1, 0); }
977
0
      break;
978
979
      /*-----------------------------------------------------------------*/
980
981
0
      case OP_DIGIT:
982
0
      case OP_WHITESPACE:
983
0
      case OP_WORDCHAR:
984
0
      if (clen > 0 && c < 256 &&
985
0
            ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0)
986
0
        { ADD_NEW(state_offset + 1, 0); }
987
0
      break;
988
989
      /*-----------------------------------------------------------------*/
990
0
      case OP_NOT_DIGIT:
991
0
      case OP_NOT_WHITESPACE:
992
0
      case OP_NOT_WORDCHAR:
993
0
      if (clen > 0 && (c >= 256 ||
994
0
            ((ctypes[c] & toptable1[codevalue]) ^ toptable2[codevalue]) != 0))
995
0
        { ADD_NEW(state_offset + 1, 0); }
996
0
      break;
997
998
      /*-----------------------------------------------------------------*/
999
0
      case OP_WORD_BOUNDARY:
1000
0
      case OP_NOT_WORD_BOUNDARY:
1001
0
        {
1002
0
        int left_word, right_word;
1003
1004
0
        if (ptr > start_subject)
1005
0
          {
1006
0
          const pcre_uchar *temp = ptr - 1;
1007
0
          if (temp < md->start_used_ptr) md->start_used_ptr = temp;
1008
0
#ifdef SUPPORT_UTF
1009
0
          if (utf) { BACKCHAR(temp); }
1010
0
#endif
1011
0
          GETCHARTEST(d, temp);
1012
0
#ifdef SUPPORT_UCP
1013
0
          if ((md->poptions & PCRE_UCP) != 0)
1014
0
            {
1015
0
            if (d == '_') left_word = TRUE; else
1016
0
              {
1017
0
              int cat = UCD_CATEGORY(d);
1018
0
              left_word = (cat == ucp_L || cat == ucp_N);
1019
0
              }
1020
0
            }
1021
0
          else
1022
0
#endif
1023
0
          left_word = d < 256 && (ctypes[d] & ctype_word) != 0;
1024
0
          }
1025
0
        else left_word = FALSE;
1026
1027
0
        if (clen > 0)
1028
0
          {
1029
0
#ifdef SUPPORT_UCP
1030
0
          if ((md->poptions & PCRE_UCP) != 0)
1031
0
            {
1032
0
            if (c == '_') right_word = TRUE; else
1033
0
              {
1034
0
              int cat = UCD_CATEGORY(c);
1035
0
              right_word = (cat == ucp_L || cat == ucp_N);
1036
0
              }
1037
0
            }
1038
0
          else
1039
0
#endif
1040
0
          right_word = c < 256 && (ctypes[c] & ctype_word) != 0;
1041
0
          }
1042
0
        else right_word = FALSE;
1043
1044
0
        if ((left_word == right_word) == (codevalue == OP_NOT_WORD_BOUNDARY))
1045
0
          { ADD_ACTIVE(state_offset + 1, 0); }
1046
0
        }
1047
0
      break;
1048
1049
1050
      /*-----------------------------------------------------------------*/
1051
      /* Check the next character by Unicode property. We will get here only
1052
      if the support is in the binary; otherwise a compile-time error occurs.
1053
      */
1054
1055
0
#ifdef SUPPORT_UCP
1056
0
      case OP_PROP:
1057
0
      case OP_NOTPROP:
1058
0
      if (clen > 0)
1059
0
        {
1060
0
        BOOL OK;
1061
0
        const pcre_uint8 chartype = UCD_CHARTYPE(c);
1062
0
        switch(code[1])
1063
0
          {
1064
0
          case PT_ANY:
1065
0
          OK = TRUE;
1066
0
          break;
1067
1068
0
          case PT_LAMP:
1069
0
          OK = chartype == ucp_Lu || chartype == ucp_Ll ||
1070
0
               chartype == ucp_Lt;
1071
0
          break;
1072
1073
0
          case PT_GC:
1074
0
          OK = PRIV(ucp_gentype)[chartype] == code[2];
1075
0
          break;
1076
1077
0
          case PT_PC:
1078
0
          OK = chartype == code[2];
1079
0
          break;
1080
1081
0
          case PT_SC:
1082
0
          OK = UCD_SCRIPT(c) == code[2];
1083
0
          break;
1084
1085
          /* These are specials for combination cases. */
1086
1087
0
          case PT_ALNUM:
1088
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1089
0
               PRIV(ucp_gentype)[chartype] == ucp_N;
1090
0
          break;
1091
1092
0
          case PT_SPACE:    /* Perl space */
1093
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1094
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1095
0
          break;
1096
1097
0
          case PT_PXSPACE:  /* POSIX space */
1098
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1099
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1100
0
               c == CHAR_FF || c == CHAR_CR;
1101
0
          break;
1102
1103
0
          case PT_WORD:
1104
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1105
0
               PRIV(ucp_gentype)[chartype] == ucp_N ||
1106
0
               c == CHAR_UNDERSCORE;
1107
0
          break;
1108
1109
          /* Should never occur, but keep compilers from grumbling. */
1110
1111
0
          default:
1112
0
          OK = codevalue != OP_PROP;
1113
0
          break;
1114
0
          }
1115
1116
0
        if (OK == (codevalue == OP_PROP)) { ADD_NEW(state_offset + 3, 0); }
1117
0
        }
1118
0
      break;
1119
0
#endif
1120
1121
1122
1123
/* ========================================================================== */
1124
      /* These opcodes likewise inspect the subject character, but have an
1125
      argument that is not a data character. It is one of these opcodes:
1126
      OP_ANY, OP_ALLANY, OP_DIGIT, OP_NOT_DIGIT, OP_WHITESPACE, OP_NOT_SPACE,
1127
      OP_WORDCHAR, OP_NOT_WORDCHAR. The value is loaded into d. */
1128
1129
0
      case OP_TYPEPLUS:
1130
0
      case OP_TYPEMINPLUS:
1131
0
      case OP_TYPEPOSPLUS:
1132
0
      count = current_state->count;  /* Already matched */
1133
0
      if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1134
0
      if (clen > 0)
1135
0
        {
1136
0
        if (d == OP_ANY && ptr + 1 >= md->end_subject &&
1137
0
            (md->moptions & (PCRE_PARTIAL_HARD)) != 0 &&
1138
0
            NLBLOCK->nltype == NLTYPE_FIXED &&
1139
0
            NLBLOCK->nllen == 2 &&
1140
0
            c == NLBLOCK->nl[0])
1141
0
          {
1142
0
          could_continue = partial_newline = TRUE;
1143
0
          }
1144
0
        else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1145
0
            (c < 256 &&
1146
0
              (d != OP_ANY || !IS_NEWLINE(ptr)) &&
1147
0
              ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1148
0
          {
1149
0
          if (count > 0 && codevalue == OP_TYPEPOSPLUS)
1150
0
            {
1151
0
            active_count--;            /* Remove non-match possibility */
1152
0
            next_active_state--;
1153
0
            }
1154
0
          count++;
1155
0
          ADD_NEW(state_offset, count);
1156
0
          }
1157
0
        }
1158
0
      break;
1159
1160
      /*-----------------------------------------------------------------*/
1161
0
      case OP_TYPEQUERY:
1162
0
      case OP_TYPEMINQUERY:
1163
0
      case OP_TYPEPOSQUERY:
1164
0
      ADD_ACTIVE(state_offset + 2, 0);
1165
0
      if (clen > 0)
1166
0
        {
1167
0
        if (d == OP_ANY && ptr + 1 >= md->end_subject &&
1168
0
            (md->moptions & (PCRE_PARTIAL_HARD)) != 0 &&
1169
0
            NLBLOCK->nltype == NLTYPE_FIXED &&
1170
0
            NLBLOCK->nllen == 2 &&
1171
0
            c == NLBLOCK->nl[0])
1172
0
          {
1173
0
          could_continue = partial_newline = TRUE;
1174
0
          }
1175
0
        else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1176
0
            (c < 256 &&
1177
0
              (d != OP_ANY || !IS_NEWLINE(ptr)) &&
1178
0
              ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1179
0
          {
1180
0
          if (codevalue == OP_TYPEPOSQUERY)
1181
0
            {
1182
0
            active_count--;            /* Remove non-match possibility */
1183
0
            next_active_state--;
1184
0
            }
1185
0
          ADD_NEW(state_offset + 2, 0);
1186
0
          }
1187
0
        }
1188
0
      break;
1189
1190
      /*-----------------------------------------------------------------*/
1191
0
      case OP_TYPESTAR:
1192
0
      case OP_TYPEMINSTAR:
1193
0
      case OP_TYPEPOSSTAR:
1194
0
      ADD_ACTIVE(state_offset + 2, 0);
1195
0
      if (clen > 0)
1196
0
        {
1197
0
        if (d == OP_ANY && ptr + 1 >= md->end_subject &&
1198
0
            (md->moptions & (PCRE_PARTIAL_HARD)) != 0 &&
1199
0
            NLBLOCK->nltype == NLTYPE_FIXED &&
1200
0
            NLBLOCK->nllen == 2 &&
1201
0
            c == NLBLOCK->nl[0])
1202
0
          {
1203
0
          could_continue = partial_newline = TRUE;
1204
0
          }
1205
0
        else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1206
0
            (c < 256 &&
1207
0
              (d != OP_ANY || !IS_NEWLINE(ptr)) &&
1208
0
              ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1209
0
          {
1210
0
          if (codevalue == OP_TYPEPOSSTAR)
1211
0
            {
1212
0
            active_count--;            /* Remove non-match possibility */
1213
0
            next_active_state--;
1214
0
            }
1215
0
          ADD_NEW(state_offset, 0);
1216
0
          }
1217
0
        }
1218
0
      break;
1219
1220
      /*-----------------------------------------------------------------*/
1221
0
      case OP_TYPEEXACT:
1222
0
      count = current_state->count;  /* Number already matched */
1223
0
      if (clen > 0)
1224
0
        {
1225
0
        if (d == OP_ANY && ptr + 1 >= md->end_subject &&
1226
0
            (md->moptions & (PCRE_PARTIAL_HARD)) != 0 &&
1227
0
            NLBLOCK->nltype == NLTYPE_FIXED &&
1228
0
            NLBLOCK->nllen == 2 &&
1229
0
            c == NLBLOCK->nl[0])
1230
0
          {
1231
0
          could_continue = partial_newline = TRUE;
1232
0
          }
1233
0
        else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1234
0
            (c < 256 &&
1235
0
              (d != OP_ANY || !IS_NEWLINE(ptr)) &&
1236
0
              ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1237
0
          {
1238
0
          if (++count >= GET2(code, 1))
1239
0
            { ADD_NEW(state_offset + 1 + IMM2_SIZE + 1, 0); }
1240
0
          else
1241
0
            { ADD_NEW(state_offset, count); }
1242
0
          }
1243
0
        }
1244
0
      break;
1245
1246
      /*-----------------------------------------------------------------*/
1247
0
      case OP_TYPEUPTO:
1248
0
      case OP_TYPEMINUPTO:
1249
0
      case OP_TYPEPOSUPTO:
1250
0
      ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0);
1251
0
      count = current_state->count;  /* Number already matched */
1252
0
      if (clen > 0)
1253
0
        {
1254
0
        if (d == OP_ANY && ptr + 1 >= md->end_subject &&
1255
0
            (md->moptions & (PCRE_PARTIAL_HARD)) != 0 &&
1256
0
            NLBLOCK->nltype == NLTYPE_FIXED &&
1257
0
            NLBLOCK->nllen == 2 &&
1258
0
            c == NLBLOCK->nl[0])
1259
0
          {
1260
0
          could_continue = partial_newline = TRUE;
1261
0
          }
1262
0
        else if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) ||
1263
0
            (c < 256 &&
1264
0
              (d != OP_ANY || !IS_NEWLINE(ptr)) &&
1265
0
              ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0))
1266
0
          {
1267
0
          if (codevalue == OP_TYPEPOSUPTO)
1268
0
            {
1269
0
            active_count--;           /* Remove non-match possibility */
1270
0
            next_active_state--;
1271
0
            }
1272
0
          if (++count >= GET2(code, 1))
1273
0
            { ADD_NEW(state_offset + 2 + IMM2_SIZE, 0); }
1274
0
          else
1275
0
            { ADD_NEW(state_offset, count); }
1276
0
          }
1277
0
        }
1278
0
      break;
1279
1280
/* ========================================================================== */
1281
      /* These are virtual opcodes that are used when something like
1282
      OP_TYPEPLUS has OP_PROP, OP_NOTPROP, OP_ANYNL, or OP_EXTUNI as its
1283
      argument. It keeps the code above fast for the other cases. The argument
1284
      is in the d variable. */
1285
1286
0
#ifdef SUPPORT_UCP
1287
0
      case OP_PROP_EXTRA + OP_TYPEPLUS:
1288
0
      case OP_PROP_EXTRA + OP_TYPEMINPLUS:
1289
0
      case OP_PROP_EXTRA + OP_TYPEPOSPLUS:
1290
0
      count = current_state->count;           /* Already matched */
1291
0
      if (count > 0) { ADD_ACTIVE(state_offset + 4, 0); }
1292
0
      if (clen > 0)
1293
0
        {
1294
0
        BOOL OK;
1295
0
        const pcre_uint8 chartype = UCD_CHARTYPE(c);
1296
0
        switch(code[2])
1297
0
          {
1298
0
          case PT_ANY:
1299
0
          OK = TRUE;
1300
0
          break;
1301
1302
0
          case PT_LAMP:
1303
0
          OK = chartype == ucp_Lu || chartype == ucp_Ll ||
1304
0
            chartype == ucp_Lt;
1305
0
          break;
1306
1307
0
          case PT_GC:
1308
0
          OK = PRIV(ucp_gentype)[chartype] == code[3];
1309
0
          break;
1310
1311
0
          case PT_PC:
1312
0
          OK = chartype == code[3];
1313
0
          break;
1314
1315
0
          case PT_SC:
1316
0
          OK = UCD_SCRIPT(c) == code[3];
1317
0
          break;
1318
1319
          /* These are specials for combination cases. */
1320
1321
0
          case PT_ALNUM:
1322
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1323
0
               PRIV(ucp_gentype)[chartype] == ucp_N;
1324
0
          break;
1325
1326
0
          case PT_SPACE:    /* Perl space */
1327
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1328
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1329
0
          break;
1330
1331
0
          case PT_PXSPACE:  /* POSIX space */
1332
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1333
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1334
0
               c == CHAR_FF || c == CHAR_CR;
1335
0
          break;
1336
1337
0
          case PT_WORD:
1338
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1339
0
               PRIV(ucp_gentype)[chartype] == ucp_N ||
1340
0
               c == CHAR_UNDERSCORE;
1341
0
          break;
1342
1343
          /* Should never occur, but keep compilers from grumbling. */
1344
1345
0
          default:
1346
0
          OK = codevalue != OP_PROP;
1347
0
          break;
1348
0
          }
1349
1350
0
        if (OK == (d == OP_PROP))
1351
0
          {
1352
0
          if (count > 0 && codevalue == OP_PROP_EXTRA + OP_TYPEPOSPLUS)
1353
0
            {
1354
0
            active_count--;           /* Remove non-match possibility */
1355
0
            next_active_state--;
1356
0
            }
1357
0
          count++;
1358
0
          ADD_NEW(state_offset, count);
1359
0
          }
1360
0
        }
1361
0
      break;
1362
1363
      /*-----------------------------------------------------------------*/
1364
0
      case OP_EXTUNI_EXTRA + OP_TYPEPLUS:
1365
0
      case OP_EXTUNI_EXTRA + OP_TYPEMINPLUS:
1366
0
      case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS:
1367
0
      count = current_state->count;  /* Already matched */
1368
0
      if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1369
0
      if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1370
0
        {
1371
0
        const pcre_uchar *nptr = ptr + clen;
1372
0
        int ncount = 0;
1373
0
        if (count > 0 && codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS)
1374
0
          {
1375
0
          active_count--;           /* Remove non-match possibility */
1376
0
          next_active_state--;
1377
0
          }
1378
0
        while (nptr < end_subject)
1379
0
          {
1380
0
          int nd;
1381
0
          int ndlen = 1;
1382
0
          GETCHARLEN(nd, nptr, ndlen);
1383
0
          if (UCD_CATEGORY(nd) != ucp_M) break;
1384
0
          ncount++;
1385
0
          nptr += ndlen;
1386
0
          }
1387
0
        count++;
1388
0
        ADD_NEW_DATA(-state_offset, count, ncount);
1389
0
        }
1390
0
      break;
1391
0
#endif
1392
1393
      /*-----------------------------------------------------------------*/
1394
0
      case OP_ANYNL_EXTRA + OP_TYPEPLUS:
1395
0
      case OP_ANYNL_EXTRA + OP_TYPEMINPLUS:
1396
0
      case OP_ANYNL_EXTRA + OP_TYPEPOSPLUS:
1397
0
      count = current_state->count;  /* Already matched */
1398
0
      if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1399
0
      if (clen > 0)
1400
0
        {
1401
0
        int ncount = 0;
1402
0
        switch (c)
1403
0
          {
1404
0
          case 0x000b:
1405
0
          case 0x000c:
1406
0
          case 0x0085:
1407
0
          case 0x2028:
1408
0
          case 0x2029:
1409
0
          if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1410
0
          goto ANYNL01;
1411
1412
0
          case 0x000d:
1413
0
          if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1414
          /* Fall through */
1415
1416
0
          ANYNL01:
1417
0
          case 0x000a:
1418
0
          if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS)
1419
0
            {
1420
0
            active_count--;           /* Remove non-match possibility */
1421
0
            next_active_state--;
1422
0
            }
1423
0
          count++;
1424
0
          ADD_NEW_DATA(-state_offset, count, ncount);
1425
0
          break;
1426
1427
0
          default:
1428
0
          break;
1429
0
          }
1430
0
        }
1431
0
      break;
1432
1433
      /*-----------------------------------------------------------------*/
1434
0
      case OP_VSPACE_EXTRA + OP_TYPEPLUS:
1435
0
      case OP_VSPACE_EXTRA + OP_TYPEMINPLUS:
1436
0
      case OP_VSPACE_EXTRA + OP_TYPEPOSPLUS:
1437
0
      count = current_state->count;  /* Already matched */
1438
0
      if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1439
0
      if (clen > 0)
1440
0
        {
1441
0
        BOOL OK;
1442
0
        switch (c)
1443
0
          {
1444
0
          case 0x000a:
1445
0
          case 0x000b:
1446
0
          case 0x000c:
1447
0
          case 0x000d:
1448
0
          case 0x0085:
1449
0
          case 0x2028:
1450
0
          case 0x2029:
1451
0
          OK = TRUE;
1452
0
          break;
1453
1454
0
          default:
1455
0
          OK = FALSE;
1456
0
          break;
1457
0
          }
1458
1459
0
        if (OK == (d == OP_VSPACE))
1460
0
          {
1461
0
          if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS)
1462
0
            {
1463
0
            active_count--;           /* Remove non-match possibility */
1464
0
            next_active_state--;
1465
0
            }
1466
0
          count++;
1467
0
          ADD_NEW_DATA(-state_offset, count, 0);
1468
0
          }
1469
0
        }
1470
0
      break;
1471
1472
      /*-----------------------------------------------------------------*/
1473
0
      case OP_HSPACE_EXTRA + OP_TYPEPLUS:
1474
0
      case OP_HSPACE_EXTRA + OP_TYPEMINPLUS:
1475
0
      case OP_HSPACE_EXTRA + OP_TYPEPOSPLUS:
1476
0
      count = current_state->count;  /* Already matched */
1477
0
      if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
1478
0
      if (clen > 0)
1479
0
        {
1480
0
        BOOL OK;
1481
0
        switch (c)
1482
0
          {
1483
0
          case 0x09:      /* HT */
1484
0
          case 0x20:      /* SPACE */
1485
0
          case 0xa0:      /* NBSP */
1486
0
          case 0x1680:    /* OGHAM SPACE MARK */
1487
0
          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1488
0
          case 0x2000:    /* EN QUAD */
1489
0
          case 0x2001:    /* EM QUAD */
1490
0
          case 0x2002:    /* EN SPACE */
1491
0
          case 0x2003:    /* EM SPACE */
1492
0
          case 0x2004:    /* THREE-PER-EM SPACE */
1493
0
          case 0x2005:    /* FOUR-PER-EM SPACE */
1494
0
          case 0x2006:    /* SIX-PER-EM SPACE */
1495
0
          case 0x2007:    /* FIGURE SPACE */
1496
0
          case 0x2008:    /* PUNCTUATION SPACE */
1497
0
          case 0x2009:    /* THIN SPACE */
1498
0
          case 0x200A:    /* HAIR SPACE */
1499
0
          case 0x202f:    /* NARROW NO-BREAK SPACE */
1500
0
          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1501
0
          case 0x3000:    /* IDEOGRAPHIC SPACE */
1502
0
          OK = TRUE;
1503
0
          break;
1504
1505
0
          default:
1506
0
          OK = FALSE;
1507
0
          break;
1508
0
          }
1509
1510
0
        if (OK == (d == OP_HSPACE))
1511
0
          {
1512
0
          if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS)
1513
0
            {
1514
0
            active_count--;           /* Remove non-match possibility */
1515
0
            next_active_state--;
1516
0
            }
1517
0
          count++;
1518
0
          ADD_NEW_DATA(-state_offset, count, 0);
1519
0
          }
1520
0
        }
1521
0
      break;
1522
1523
      /*-----------------------------------------------------------------*/
1524
0
#ifdef SUPPORT_UCP
1525
0
      case OP_PROP_EXTRA + OP_TYPEQUERY:
1526
0
      case OP_PROP_EXTRA + OP_TYPEMINQUERY:
1527
0
      case OP_PROP_EXTRA + OP_TYPEPOSQUERY:
1528
0
      count = 4;
1529
0
      goto QS1;
1530
1531
0
      case OP_PROP_EXTRA + OP_TYPESTAR:
1532
0
      case OP_PROP_EXTRA + OP_TYPEMINSTAR:
1533
0
      case OP_PROP_EXTRA + OP_TYPEPOSSTAR:
1534
0
      count = 0;
1535
1536
0
      QS1:
1537
1538
0
      ADD_ACTIVE(state_offset + 4, 0);
1539
0
      if (clen > 0)
1540
0
        {
1541
0
        BOOL OK;
1542
0
        const pcre_uint8 chartype = UCD_CHARTYPE(c);
1543
0
        switch(code[2])
1544
0
          {
1545
0
          case PT_ANY:
1546
0
          OK = TRUE;
1547
0
          break;
1548
1549
0
          case PT_LAMP:
1550
0
          OK = chartype == ucp_Lu || chartype == ucp_Ll ||
1551
0
            chartype == ucp_Lt;
1552
0
          break;
1553
1554
0
          case PT_GC:
1555
0
          OK = PRIV(ucp_gentype)[chartype] == code[3];
1556
0
          break;
1557
1558
0
          case PT_PC:
1559
0
          OK = chartype == code[3];
1560
0
          break;
1561
1562
0
          case PT_SC:
1563
0
          OK = UCD_SCRIPT(c) == code[3];
1564
0
          break;
1565
1566
          /* These are specials for combination cases. */
1567
1568
0
          case PT_ALNUM:
1569
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1570
0
               PRIV(ucp_gentype)[chartype] == ucp_N;
1571
0
          break;
1572
1573
0
          case PT_SPACE:    /* Perl space */
1574
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1575
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1576
0
          break;
1577
1578
0
          case PT_PXSPACE:  /* POSIX space */
1579
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1580
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1581
0
               c == CHAR_FF || c == CHAR_CR;
1582
0
          break;
1583
1584
0
          case PT_WORD:
1585
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1586
0
               PRIV(ucp_gentype)[chartype] == ucp_N ||
1587
0
               c == CHAR_UNDERSCORE;
1588
0
          break;
1589
1590
          /* Should never occur, but keep compilers from grumbling. */
1591
1592
0
          default:
1593
0
          OK = codevalue != OP_PROP;
1594
0
          break;
1595
0
          }
1596
1597
0
        if (OK == (d == OP_PROP))
1598
0
          {
1599
0
          if (codevalue == OP_PROP_EXTRA + OP_TYPEPOSSTAR ||
1600
0
              codevalue == OP_PROP_EXTRA + OP_TYPEPOSQUERY)
1601
0
            {
1602
0
            active_count--;           /* Remove non-match possibility */
1603
0
            next_active_state--;
1604
0
            }
1605
0
          ADD_NEW(state_offset + count, 0);
1606
0
          }
1607
0
        }
1608
0
      break;
1609
1610
      /*-----------------------------------------------------------------*/
1611
0
      case OP_EXTUNI_EXTRA + OP_TYPEQUERY:
1612
0
      case OP_EXTUNI_EXTRA + OP_TYPEMINQUERY:
1613
0
      case OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY:
1614
0
      count = 2;
1615
0
      goto QS2;
1616
1617
0
      case OP_EXTUNI_EXTRA + OP_TYPESTAR:
1618
0
      case OP_EXTUNI_EXTRA + OP_TYPEMINSTAR:
1619
0
      case OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR:
1620
0
      count = 0;
1621
1622
0
      QS2:
1623
1624
0
      ADD_ACTIVE(state_offset + 2, 0);
1625
0
      if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1626
0
        {
1627
0
        const pcre_uchar *nptr = ptr + clen;
1628
0
        int ncount = 0;
1629
0
        if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR ||
1630
0
            codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY)
1631
0
          {
1632
0
          active_count--;           /* Remove non-match possibility */
1633
0
          next_active_state--;
1634
0
          }
1635
0
        while (nptr < end_subject)
1636
0
          {
1637
0
          int nd;
1638
0
          int ndlen = 1;
1639
0
          GETCHARLEN(nd, nptr, ndlen);
1640
0
          if (UCD_CATEGORY(nd) != ucp_M) break;
1641
0
          ncount++;
1642
0
          nptr += ndlen;
1643
0
          }
1644
0
        ADD_NEW_DATA(-(state_offset + count), 0, ncount);
1645
0
        }
1646
0
      break;
1647
0
#endif
1648
1649
      /*-----------------------------------------------------------------*/
1650
0
      case OP_ANYNL_EXTRA + OP_TYPEQUERY:
1651
0
      case OP_ANYNL_EXTRA + OP_TYPEMINQUERY:
1652
0
      case OP_ANYNL_EXTRA + OP_TYPEPOSQUERY:
1653
0
      count = 2;
1654
0
      goto QS3;
1655
1656
0
      case OP_ANYNL_EXTRA + OP_TYPESTAR:
1657
0
      case OP_ANYNL_EXTRA + OP_TYPEMINSTAR:
1658
0
      case OP_ANYNL_EXTRA + OP_TYPEPOSSTAR:
1659
0
      count = 0;
1660
1661
0
      QS3:
1662
0
      ADD_ACTIVE(state_offset + 2, 0);
1663
0
      if (clen > 0)
1664
0
        {
1665
0
        int ncount = 0;
1666
0
        switch (c)
1667
0
          {
1668
0
          case 0x000b:
1669
0
          case 0x000c:
1670
0
          case 0x0085:
1671
0
          case 0x2028:
1672
0
          case 0x2029:
1673
0
          if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1674
0
          goto ANYNL02;
1675
1676
0
          case 0x000d:
1677
0
          if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1678
          /* Fall through */
1679
1680
0
          ANYNL02:
1681
0
          case 0x000a:
1682
0
          if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR ||
1683
0
              codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY)
1684
0
            {
1685
0
            active_count--;           /* Remove non-match possibility */
1686
0
            next_active_state--;
1687
0
            }
1688
0
          ADD_NEW_DATA(-(state_offset + count), 0, ncount);
1689
0
          break;
1690
1691
0
          default:
1692
0
          break;
1693
0
          }
1694
0
        }
1695
0
      break;
1696
1697
      /*-----------------------------------------------------------------*/
1698
0
      case OP_VSPACE_EXTRA + OP_TYPEQUERY:
1699
0
      case OP_VSPACE_EXTRA + OP_TYPEMINQUERY:
1700
0
      case OP_VSPACE_EXTRA + OP_TYPEPOSQUERY:
1701
0
      count = 2;
1702
0
      goto QS4;
1703
1704
0
      case OP_VSPACE_EXTRA + OP_TYPESTAR:
1705
0
      case OP_VSPACE_EXTRA + OP_TYPEMINSTAR:
1706
0
      case OP_VSPACE_EXTRA + OP_TYPEPOSSTAR:
1707
0
      count = 0;
1708
1709
0
      QS4:
1710
0
      ADD_ACTIVE(state_offset + 2, 0);
1711
0
      if (clen > 0)
1712
0
        {
1713
0
        BOOL OK;
1714
0
        switch (c)
1715
0
          {
1716
0
          case 0x000a:
1717
0
          case 0x000b:
1718
0
          case 0x000c:
1719
0
          case 0x000d:
1720
0
          case 0x0085:
1721
0
          case 0x2028:
1722
0
          case 0x2029:
1723
0
          OK = TRUE;
1724
0
          break;
1725
1726
0
          default:
1727
0
          OK = FALSE;
1728
0
          break;
1729
0
          }
1730
0
        if (OK == (d == OP_VSPACE))
1731
0
          {
1732
0
          if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSSTAR ||
1733
0
              codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSQUERY)
1734
0
            {
1735
0
            active_count--;           /* Remove non-match possibility */
1736
0
            next_active_state--;
1737
0
            }
1738
0
          ADD_NEW_DATA(-(state_offset + count), 0, 0);
1739
0
          }
1740
0
        }
1741
0
      break;
1742
1743
      /*-----------------------------------------------------------------*/
1744
0
      case OP_HSPACE_EXTRA + OP_TYPEQUERY:
1745
0
      case OP_HSPACE_EXTRA + OP_TYPEMINQUERY:
1746
0
      case OP_HSPACE_EXTRA + OP_TYPEPOSQUERY:
1747
0
      count = 2;
1748
0
      goto QS5;
1749
1750
0
      case OP_HSPACE_EXTRA + OP_TYPESTAR:
1751
0
      case OP_HSPACE_EXTRA + OP_TYPEMINSTAR:
1752
0
      case OP_HSPACE_EXTRA + OP_TYPEPOSSTAR:
1753
0
      count = 0;
1754
1755
0
      QS5:
1756
0
      ADD_ACTIVE(state_offset + 2, 0);
1757
0
      if (clen > 0)
1758
0
        {
1759
0
        BOOL OK;
1760
0
        switch (c)
1761
0
          {
1762
0
          case 0x09:      /* HT */
1763
0
          case 0x20:      /* SPACE */
1764
0
          case 0xa0:      /* NBSP */
1765
0
          case 0x1680:    /* OGHAM SPACE MARK */
1766
0
          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1767
0
          case 0x2000:    /* EN QUAD */
1768
0
          case 0x2001:    /* EM QUAD */
1769
0
          case 0x2002:    /* EN SPACE */
1770
0
          case 0x2003:    /* EM SPACE */
1771
0
          case 0x2004:    /* THREE-PER-EM SPACE */
1772
0
          case 0x2005:    /* FOUR-PER-EM SPACE */
1773
0
          case 0x2006:    /* SIX-PER-EM SPACE */
1774
0
          case 0x2007:    /* FIGURE SPACE */
1775
0
          case 0x2008:    /* PUNCTUATION SPACE */
1776
0
          case 0x2009:    /* THIN SPACE */
1777
0
          case 0x200A:    /* HAIR SPACE */
1778
0
          case 0x202f:    /* NARROW NO-BREAK SPACE */
1779
0
          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1780
0
          case 0x3000:    /* IDEOGRAPHIC SPACE */
1781
0
          OK = TRUE;
1782
0
          break;
1783
1784
0
          default:
1785
0
          OK = FALSE;
1786
0
          break;
1787
0
          }
1788
1789
0
        if (OK == (d == OP_HSPACE))
1790
0
          {
1791
0
          if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSSTAR ||
1792
0
              codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSQUERY)
1793
0
            {
1794
0
            active_count--;           /* Remove non-match possibility */
1795
0
            next_active_state--;
1796
0
            }
1797
0
          ADD_NEW_DATA(-(state_offset + count), 0, 0);
1798
0
          }
1799
0
        }
1800
0
      break;
1801
1802
      /*-----------------------------------------------------------------*/
1803
0
#ifdef SUPPORT_UCP
1804
0
      case OP_PROP_EXTRA + OP_TYPEEXACT:
1805
0
      case OP_PROP_EXTRA + OP_TYPEUPTO:
1806
0
      case OP_PROP_EXTRA + OP_TYPEMINUPTO:
1807
0
      case OP_PROP_EXTRA + OP_TYPEPOSUPTO:
1808
0
      if (codevalue != OP_PROP_EXTRA + OP_TYPEEXACT)
1809
0
        { ADD_ACTIVE(state_offset + 1 + IMM2_SIZE + 3, 0); }
1810
0
      count = current_state->count;  /* Number already matched */
1811
0
      if (clen > 0)
1812
0
        {
1813
0
        BOOL OK;
1814
0
        const pcre_uint8 chartype = UCD_CHARTYPE(c);
1815
0
        switch(code[1 + IMM2_SIZE + 1])
1816
0
          {
1817
0
          case PT_ANY:
1818
0
          OK = TRUE;
1819
0
          break;
1820
1821
0
          case PT_LAMP:
1822
0
          OK = chartype == ucp_Lu || chartype == ucp_Ll ||
1823
0
            chartype == ucp_Lt;
1824
0
          break;
1825
1826
0
          case PT_GC:
1827
0
          OK = PRIV(ucp_gentype)[chartype] == code[1 + IMM2_SIZE + 2];
1828
0
          break;
1829
1830
0
          case PT_PC:
1831
0
          OK = chartype == code[1 + IMM2_SIZE + 2];
1832
0
          break;
1833
1834
0
          case PT_SC:
1835
0
          OK = UCD_SCRIPT(c) == code[1 + IMM2_SIZE + 2];
1836
0
          break;
1837
1838
          /* These are specials for combination cases. */
1839
1840
0
          case PT_ALNUM:
1841
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1842
0
               PRIV(ucp_gentype)[chartype] == ucp_N;
1843
0
          break;
1844
1845
0
          case PT_SPACE:    /* Perl space */
1846
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1847
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR;
1848
0
          break;
1849
1850
0
          case PT_PXSPACE:  /* POSIX space */
1851
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_Z ||
1852
0
               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
1853
0
               c == CHAR_FF || c == CHAR_CR;
1854
0
          break;
1855
1856
0
          case PT_WORD:
1857
0
          OK = PRIV(ucp_gentype)[chartype] == ucp_L ||
1858
0
               PRIV(ucp_gentype)[chartype] == ucp_N ||
1859
0
               c == CHAR_UNDERSCORE;
1860
0
          break;
1861
1862
          /* Should never occur, but keep compilers from grumbling. */
1863
1864
0
          default:
1865
0
          OK = codevalue != OP_PROP;
1866
0
          break;
1867
0
          }
1868
1869
0
        if (OK == (d == OP_PROP))
1870
0
          {
1871
0
          if (codevalue == OP_PROP_EXTRA + OP_TYPEPOSUPTO)
1872
0
            {
1873
0
            active_count--;           /* Remove non-match possibility */
1874
0
            next_active_state--;
1875
0
            }
1876
0
          if (++count >= GET2(code, 1))
1877
0
            { ADD_NEW(state_offset + 1 + IMM2_SIZE + 3, 0); }
1878
0
          else
1879
0
            { ADD_NEW(state_offset, count); }
1880
0
          }
1881
0
        }
1882
0
      break;
1883
1884
      /*-----------------------------------------------------------------*/
1885
0
      case OP_EXTUNI_EXTRA + OP_TYPEEXACT:
1886
0
      case OP_EXTUNI_EXTRA + OP_TYPEUPTO:
1887
0
      case OP_EXTUNI_EXTRA + OP_TYPEMINUPTO:
1888
0
      case OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO:
1889
0
      if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT)
1890
0
        { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); }
1891
0
      count = current_state->count;  /* Number already matched */
1892
0
      if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
1893
0
        {
1894
0
        const pcre_uchar *nptr = ptr + clen;
1895
0
        int ncount = 0;
1896
0
        if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO)
1897
0
          {
1898
0
          active_count--;           /* Remove non-match possibility */
1899
0
          next_active_state--;
1900
0
          }
1901
0
        while (nptr < end_subject)
1902
0
          {
1903
0
          int nd;
1904
0
          int ndlen = 1;
1905
0
          GETCHARLEN(nd, nptr, ndlen);
1906
0
          if (UCD_CATEGORY(nd) != ucp_M) break;
1907
0
          ncount++;
1908
0
          nptr += ndlen;
1909
0
          }
1910
0
        if (nptr >= end_subject && (md->moptions & PCRE_PARTIAL_HARD) != 0)
1911
0
            reset_could_continue = TRUE;
1912
0
        if (++count >= GET2(code, 1))
1913
0
          { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, ncount); }
1914
0
        else
1915
0
          { ADD_NEW_DATA(-state_offset, count, ncount); }
1916
0
        }
1917
0
      break;
1918
0
#endif
1919
1920
      /*-----------------------------------------------------------------*/
1921
0
      case OP_ANYNL_EXTRA + OP_TYPEEXACT:
1922
0
      case OP_ANYNL_EXTRA + OP_TYPEUPTO:
1923
0
      case OP_ANYNL_EXTRA + OP_TYPEMINUPTO:
1924
0
      case OP_ANYNL_EXTRA + OP_TYPEPOSUPTO:
1925
0
      if (codevalue != OP_ANYNL_EXTRA + OP_TYPEEXACT)
1926
0
        { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); }
1927
0
      count = current_state->count;  /* Number already matched */
1928
0
      if (clen > 0)
1929
0
        {
1930
0
        int ncount = 0;
1931
0
        switch (c)
1932
0
          {
1933
0
          case 0x000b:
1934
0
          case 0x000c:
1935
0
          case 0x0085:
1936
0
          case 0x2028:
1937
0
          case 0x2029:
1938
0
          if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
1939
0
          goto ANYNL03;
1940
1941
0
          case 0x000d:
1942
0
          if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1;
1943
          /* Fall through */
1944
1945
0
          ANYNL03:
1946
0
          case 0x000a:
1947
0
          if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO)
1948
0
            {
1949
0
            active_count--;           /* Remove non-match possibility */
1950
0
            next_active_state--;
1951
0
            }
1952
0
          if (++count >= GET2(code, 1))
1953
0
            { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, ncount); }
1954
0
          else
1955
0
            { ADD_NEW_DATA(-state_offset, count, ncount); }
1956
0
          break;
1957
1958
0
          default:
1959
0
          break;
1960
0
          }
1961
0
        }
1962
0
      break;
1963
1964
      /*-----------------------------------------------------------------*/
1965
0
      case OP_VSPACE_EXTRA + OP_TYPEEXACT:
1966
0
      case OP_VSPACE_EXTRA + OP_TYPEUPTO:
1967
0
      case OP_VSPACE_EXTRA + OP_TYPEMINUPTO:
1968
0
      case OP_VSPACE_EXTRA + OP_TYPEPOSUPTO:
1969
0
      if (codevalue != OP_VSPACE_EXTRA + OP_TYPEEXACT)
1970
0
        { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); }
1971
0
      count = current_state->count;  /* Number already matched */
1972
0
      if (clen > 0)
1973
0
        {
1974
0
        BOOL OK;
1975
0
        switch (c)
1976
0
          {
1977
0
          case 0x000a:
1978
0
          case 0x000b:
1979
0
          case 0x000c:
1980
0
          case 0x000d:
1981
0
          case 0x0085:
1982
0
          case 0x2028:
1983
0
          case 0x2029:
1984
0
          OK = TRUE;
1985
0
          break;
1986
1987
0
          default:
1988
0
          OK = FALSE;
1989
0
          }
1990
1991
0
        if (OK == (d == OP_VSPACE))
1992
0
          {
1993
0
          if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSUPTO)
1994
0
            {
1995
0
            active_count--;           /* Remove non-match possibility */
1996
0
            next_active_state--;
1997
0
            }
1998
0
          if (++count >= GET2(code, 1))
1999
0
            { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, 0); }
2000
0
          else
2001
0
            { ADD_NEW_DATA(-state_offset, count, 0); }
2002
0
          }
2003
0
        }
2004
0
      break;
2005
2006
      /*-----------------------------------------------------------------*/
2007
0
      case OP_HSPACE_EXTRA + OP_TYPEEXACT:
2008
0
      case OP_HSPACE_EXTRA + OP_TYPEUPTO:
2009
0
      case OP_HSPACE_EXTRA + OP_TYPEMINUPTO:
2010
0
      case OP_HSPACE_EXTRA + OP_TYPEPOSUPTO:
2011
0
      if (codevalue != OP_HSPACE_EXTRA + OP_TYPEEXACT)
2012
0
        { ADD_ACTIVE(state_offset + 2 + IMM2_SIZE, 0); }
2013
0
      count = current_state->count;  /* Number already matched */
2014
0
      if (clen > 0)
2015
0
        {
2016
0
        BOOL OK;
2017
0
        switch (c)
2018
0
          {
2019
0
          case 0x09:      /* HT */
2020
0
          case 0x20:      /* SPACE */
2021
0
          case 0xa0:      /* NBSP */
2022
0
          case 0x1680:    /* OGHAM SPACE MARK */
2023
0
          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2024
0
          case 0x2000:    /* EN QUAD */
2025
0
          case 0x2001:    /* EM QUAD */
2026
0
          case 0x2002:    /* EN SPACE */
2027
0
          case 0x2003:    /* EM SPACE */
2028
0
          case 0x2004:    /* THREE-PER-EM SPACE */
2029
0
          case 0x2005:    /* FOUR-PER-EM SPACE */
2030
0
          case 0x2006:    /* SIX-PER-EM SPACE */
2031
0
          case 0x2007:    /* FIGURE SPACE */
2032
0
          case 0x2008:    /* PUNCTUATION SPACE */
2033
0
          case 0x2009:    /* THIN SPACE */
2034
0
          case 0x200A:    /* HAIR SPACE */
2035
0
          case 0x202f:    /* NARROW NO-BREAK SPACE */
2036
0
          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2037
0
          case 0x3000:    /* IDEOGRAPHIC SPACE */
2038
0
          OK = TRUE;
2039
0
          break;
2040
2041
0
          default:
2042
0
          OK = FALSE;
2043
0
          break;
2044
0
          }
2045
2046
0
        if (OK == (d == OP_HSPACE))
2047
0
          {
2048
0
          if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSUPTO)
2049
0
            {
2050
0
            active_count--;           /* Remove non-match possibility */
2051
0
            next_active_state--;
2052
0
            }
2053
0
          if (++count >= GET2(code, 1))
2054
0
            { ADD_NEW_DATA(-(state_offset + 2 + IMM2_SIZE), 0, 0); }
2055
0
          else
2056
0
            { ADD_NEW_DATA(-state_offset, count, 0); }
2057
0
          }
2058
0
        }
2059
0
      break;
2060
2061
/* ========================================================================== */
2062
      /* These opcodes are followed by a character that is usually compared
2063
      to the current subject character; it is loaded into d. We still get
2064
      here even if there is no subject character, because in some cases zero
2065
      repetitions are permitted. */
2066
2067
      /*-----------------------------------------------------------------*/
2068
0
      case OP_CHAR:
2069
0
      if (clen > 0 && c == d) { ADD_NEW(state_offset + dlen + 1, 0); }
2070
0
      break;
2071
2072
      /*-----------------------------------------------------------------*/
2073
0
      case OP_CHARI:
2074
0
      if (clen == 0) break;
2075
2076
0
#ifdef SUPPORT_UTF
2077
0
      if (utf)
2078
0
        {
2079
0
        if (c == d) { ADD_NEW(state_offset + dlen + 1, 0); } else
2080
0
          {
2081
0
          unsigned int othercase;
2082
0
          if (c < 128)
2083
0
            othercase = fcc[c];
2084
0
          else
2085
            /* If we have Unicode property support, we can use it to test the
2086
            other case of the character. */
2087
0
#ifdef SUPPORT_UCP
2088
0
            othercase = UCD_OTHERCASE(c);
2089
#else
2090
            othercase = NOTACHAR;
2091
#endif
2092
2093
0
          if (d == othercase) { ADD_NEW(state_offset + dlen + 1, 0); }
2094
0
          }
2095
0
        }
2096
0
      else
2097
0
#endif  /* SUPPORT_UTF */
2098
      /* Not UTF mode */
2099
0
        {
2100
0
        if (TABLE_GET(c, lcc, c) == TABLE_GET(d, lcc, d))
2101
0
          { ADD_NEW(state_offset + 2, 0); }
2102
0
        }
2103
0
      break;
2104
2105
2106
0
#ifdef SUPPORT_UCP
2107
      /*-----------------------------------------------------------------*/
2108
      /* This is a tricky one because it can match more than one character.
2109
      Find out how many characters to skip, and then set up a negative state
2110
      to wait for them to pass before continuing. */
2111
2112
0
      case OP_EXTUNI:
2113
0
      if (clen > 0 && UCD_CATEGORY(c) != ucp_M)
2114
0
        {
2115
0
        const pcre_uchar *nptr = ptr + clen;
2116
0
        int ncount = 0;
2117
0
        while (nptr < end_subject)
2118
0
          {
2119
0
          int nclen = 1;
2120
0
          GETCHARLEN(c, nptr, nclen);
2121
0
          if (UCD_CATEGORY(c) != ucp_M) break;
2122
0
          ncount++;
2123
0
          nptr += nclen;
2124
0
          }
2125
0
        if (nptr >= end_subject && (md->moptions & PCRE_PARTIAL_HARD) != 0)
2126
0
            reset_could_continue = TRUE;
2127
0
        ADD_NEW_DATA(-(state_offset + 1), 0, ncount);
2128
0
        }
2129
0
      break;
2130
0
#endif
2131
2132
      /*-----------------------------------------------------------------*/
2133
      /* This is a tricky like EXTUNI because it too can match more than one
2134
      character (when CR is followed by LF). In this case, set up a negative
2135
      state to wait for one character to pass before continuing. */
2136
2137
0
      case OP_ANYNL:
2138
0
      if (clen > 0) switch(c)
2139
0
        {
2140
0
        case 0x000b:
2141
0
        case 0x000c:
2142
0
        case 0x0085:
2143
0
        case 0x2028:
2144
0
        case 0x2029:
2145
0
        if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break;
2146
2147
0
        case 0x000a:
2148
0
        ADD_NEW(state_offset + 1, 0);
2149
0
        break;
2150
2151
0
        case 0x000d:
2152
0
        if (ptr + 1 >= end_subject)
2153
0
          {
2154
0
          ADD_NEW(state_offset + 1, 0);
2155
0
          if ((md->moptions & PCRE_PARTIAL_HARD) != 0)
2156
0
            reset_could_continue = TRUE;
2157
0
          }
2158
0
        else if (ptr[1] == 0x0a)
2159
0
          {
2160
0
          ADD_NEW_DATA(-(state_offset + 1), 0, 1);
2161
0
          }
2162
0
        else
2163
0
          {
2164
0
          ADD_NEW(state_offset + 1, 0);
2165
0
          }
2166
0
        break;
2167
0
        }
2168
0
      break;
2169
2170
      /*-----------------------------------------------------------------*/
2171
0
      case OP_NOT_VSPACE:
2172
0
      if (clen > 0) switch(c)
2173
0
        {
2174
0
        case 0x000a:
2175
0
        case 0x000b:
2176
0
        case 0x000c:
2177
0
        case 0x000d:
2178
0
        case 0x0085:
2179
0
        case 0x2028:
2180
0
        case 0x2029:
2181
0
        break;
2182
2183
0
        default:
2184
0
        ADD_NEW(state_offset + 1, 0);
2185
0
        break;
2186
0
        }
2187
0
      break;
2188
2189
      /*-----------------------------------------------------------------*/
2190
0
      case OP_VSPACE:
2191
0
      if (clen > 0) switch(c)
2192
0
        {
2193
0
        case 0x000a:
2194
0
        case 0x000b:
2195
0
        case 0x000c:
2196
0
        case 0x000d:
2197
0
        case 0x0085:
2198
0
        case 0x2028:
2199
0
        case 0x2029:
2200
0
        ADD_NEW(state_offset + 1, 0);
2201
0
        break;
2202
2203
0
        default: break;
2204
0
        }
2205
0
      break;
2206
2207
      /*-----------------------------------------------------------------*/
2208
0
      case OP_NOT_HSPACE:
2209
0
      if (clen > 0) switch(c)
2210
0
        {
2211
0
        case 0x09:      /* HT */
2212
0
        case 0x20:      /* SPACE */
2213
0
        case 0xa0:      /* NBSP */
2214
0
        case 0x1680:    /* OGHAM SPACE MARK */
2215
0
        case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2216
0
        case 0x2000:    /* EN QUAD */
2217
0
        case 0x2001:    /* EM QUAD */
2218
0
        case 0x2002:    /* EN SPACE */
2219
0
        case 0x2003:    /* EM SPACE */
2220
0
        case 0x2004:    /* THREE-PER-EM SPACE */
2221
0
        case 0x2005:    /* FOUR-PER-EM SPACE */
2222
0
        case 0x2006:    /* SIX-PER-EM SPACE */
2223
0
        case 0x2007:    /* FIGURE SPACE */
2224
0
        case 0x2008:    /* PUNCTUATION SPACE */
2225
0
        case 0x2009:    /* THIN SPACE */
2226
0
        case 0x200A:    /* HAIR SPACE */
2227
0
        case 0x202f:    /* NARROW NO-BREAK SPACE */
2228
0
        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2229
0
        case 0x3000:    /* IDEOGRAPHIC SPACE */
2230
0
        break;
2231
2232
0
        default:
2233
0
        ADD_NEW(state_offset + 1, 0);
2234
0
        break;
2235
0
        }
2236
0
      break;
2237
2238
      /*-----------------------------------------------------------------*/
2239
0
      case OP_HSPACE:
2240
0
      if (clen > 0) switch(c)
2241
0
        {
2242
0
        case 0x09:      /* HT */
2243
0
        case 0x20:      /* SPACE */
2244
0
        case 0xa0:      /* NBSP */
2245
0
        case 0x1680:    /* OGHAM SPACE MARK */
2246
0
        case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2247
0
        case 0x2000:    /* EN QUAD */
2248
0
        case 0x2001:    /* EM QUAD */
2249
0
        case 0x2002:    /* EN SPACE */
2250
0
        case 0x2003:    /* EM SPACE */
2251
0
        case 0x2004:    /* THREE-PER-EM SPACE */
2252
0
        case 0x2005:    /* FOUR-PER-EM SPACE */
2253
0
        case 0x2006:    /* SIX-PER-EM SPACE */
2254
0
        case 0x2007:    /* FIGURE SPACE */
2255
0
        case 0x2008:    /* PUNCTUATION SPACE */
2256
0
        case 0x2009:    /* THIN SPACE */
2257
0
        case 0x200A:    /* HAIR SPACE */
2258
0
        case 0x202f:    /* NARROW NO-BREAK SPACE */
2259
0
        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2260
0
        case 0x3000:    /* IDEOGRAPHIC SPACE */
2261
0
        ADD_NEW(state_offset + 1, 0);
2262
0
        break;
2263
0
        }
2264
0
      break;
2265
2266
      /*-----------------------------------------------------------------*/
2267
      /* Match a negated single character casefully. */
2268
2269
0
      case OP_NOT:
2270
0
      if (clen > 0 && c != d) { ADD_NEW(state_offset + dlen + 1, 0); }
2271
0
      break;
2272
2273
      /*-----------------------------------------------------------------*/
2274
      /* Match a negated single character caselessly. */
2275
2276
0
      case OP_NOTI:
2277
0
      if (clen > 0)
2278
0
        {
2279
0
        unsigned int otherd;
2280
0
#ifdef SUPPORT_UTF
2281
0
        if (utf && d >= 128)
2282
0
          {
2283
0
#ifdef SUPPORT_UCP
2284
0
          otherd = UCD_OTHERCASE(d);
2285
0
#endif  /* SUPPORT_UCP */
2286
0
          }
2287
0
        else
2288
0
#endif  /* SUPPORT_UTF */
2289
0
        otherd = TABLE_GET(d, fcc, d);
2290
0
        if (c != d && c != otherd)
2291
0
          { ADD_NEW(state_offset + dlen + 1, 0); }
2292
0
        }
2293
0
      break;
2294
2295
      /*-----------------------------------------------------------------*/
2296
0
      case OP_PLUSI:
2297
0
      case OP_MINPLUSI:
2298
0
      case OP_POSPLUSI:
2299
0
      case OP_NOTPLUSI:
2300
0
      case OP_NOTMINPLUSI:
2301
0
      case OP_NOTPOSPLUSI:
2302
0
      caseless = TRUE;
2303
0
      codevalue -= OP_STARI - OP_STAR;
2304
2305
      /* Fall through */
2306
0
      case OP_PLUS:
2307
0
      case OP_MINPLUS:
2308
0
      case OP_POSPLUS:
2309
0
      case OP_NOTPLUS:
2310
0
      case OP_NOTMINPLUS:
2311
0
      case OP_NOTPOSPLUS:
2312
0
      count = current_state->count;  /* Already matched */
2313
0
      if (count > 0) { ADD_ACTIVE(state_offset + dlen + 1, 0); }
2314
0
      if (clen > 0)
2315
0
        {
2316
0
        unsigned int otherd = NOTACHAR;
2317
0
        if (caseless)
2318
0
          {
2319
0
#ifdef SUPPORT_UTF
2320
0
          if (utf && d >= 128)
2321
0
            {
2322
0
#ifdef SUPPORT_UCP
2323
0
            otherd = UCD_OTHERCASE(d);
2324
0
#endif  /* SUPPORT_UCP */
2325
0
            }
2326
0
          else
2327
0
#endif  /* SUPPORT_UTF */
2328
0
          otherd = TABLE_GET(d, fcc, d);
2329
0
          }
2330
0
        if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
2331
0
          {
2332
0
          if (count > 0 &&
2333
0
              (codevalue == OP_POSPLUS || codevalue == OP_NOTPOSPLUS))
2334
0
            {
2335
0
            active_count--;             /* Remove non-match possibility */
2336
0
            next_active_state--;
2337
0
            }
2338
0
          count++;
2339
0
          ADD_NEW(state_offset, count);
2340
0
          }
2341
0
        }
2342
0
      break;
2343
2344
      /*-----------------------------------------------------------------*/
2345
0
      case OP_QUERYI:
2346
0
      case OP_MINQUERYI:
2347
0
      case OP_POSQUERYI:
2348
0
      case OP_NOTQUERYI:
2349
0
      case OP_NOTMINQUERYI:
2350
0
      case OP_NOTPOSQUERYI:
2351
0
      caseless = TRUE;
2352
0
      codevalue -= OP_STARI - OP_STAR;
2353
      /* Fall through */
2354
0
      case OP_QUERY:
2355
0
      case OP_MINQUERY:
2356
0
      case OP_POSQUERY:
2357
0
      case OP_NOTQUERY:
2358
0
      case OP_NOTMINQUERY:
2359
0
      case OP_NOTPOSQUERY:
2360
0
      ADD_ACTIVE(state_offset + dlen + 1, 0);
2361
0
      if (clen > 0)
2362
0
        {
2363
0
        unsigned int otherd = NOTACHAR;
2364
0
        if (caseless)
2365
0
          {
2366
0
#ifdef SUPPORT_UTF
2367
0
          if (utf && d >= 128)
2368
0
            {
2369
0
#ifdef SUPPORT_UCP
2370
0
            otherd = UCD_OTHERCASE(d);
2371
0
#endif  /* SUPPORT_UCP */
2372
0
            }
2373
0
          else
2374
0
#endif  /* SUPPORT_UTF */
2375
0
          otherd = TABLE_GET(d, fcc, d);
2376
0
          }
2377
0
        if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
2378
0
          {
2379
0
          if (codevalue == OP_POSQUERY || codevalue == OP_NOTPOSQUERY)
2380
0
            {
2381
0
            active_count--;            /* Remove non-match possibility */
2382
0
            next_active_state--;
2383
0
            }
2384
0
          ADD_NEW(state_offset + dlen + 1, 0);
2385
0
          }
2386
0
        }
2387
0
      break;
2388
2389
      /*-----------------------------------------------------------------*/
2390
0
      case OP_STARI:
2391
0
      case OP_MINSTARI:
2392
0
      case OP_POSSTARI:
2393
0
      case OP_NOTSTARI:
2394
0
      case OP_NOTMINSTARI:
2395
0
      case OP_NOTPOSSTARI:
2396
0
      caseless = TRUE;
2397
0
      codevalue -= OP_STARI - OP_STAR;
2398
      /* Fall through */
2399
0
      case OP_STAR:
2400
0
      case OP_MINSTAR:
2401
0
      case OP_POSSTAR:
2402
0
      case OP_NOTSTAR:
2403
0
      case OP_NOTMINSTAR:
2404
0
      case OP_NOTPOSSTAR:
2405
0
      ADD_ACTIVE(state_offset + dlen + 1, 0);
2406
0
      if (clen > 0)
2407
0
        {
2408
0
        unsigned int otherd = NOTACHAR;
2409
0
        if (caseless)
2410
0
          {
2411
0
#ifdef SUPPORT_UTF
2412
0
          if (utf && d >= 128)
2413
0
            {
2414
0
#ifdef SUPPORT_UCP
2415
0
            otherd = UCD_OTHERCASE(d);
2416
0
#endif  /* SUPPORT_UCP */
2417
0
            }
2418
0
          else
2419
0
#endif  /* SUPPORT_UTF */
2420
0
          otherd = TABLE_GET(d, fcc, d);
2421
0
          }
2422
0
        if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
2423
0
          {
2424
0
          if (codevalue == OP_POSSTAR || codevalue == OP_NOTPOSSTAR)
2425
0
            {
2426
0
            active_count--;            /* Remove non-match possibility */
2427
0
            next_active_state--;
2428
0
            }
2429
0
          ADD_NEW(state_offset, 0);
2430
0
          }
2431
0
        }
2432
0
      break;
2433
2434
      /*-----------------------------------------------------------------*/
2435
0
      case OP_EXACTI:
2436
0
      case OP_NOTEXACTI:
2437
0
      caseless = TRUE;
2438
0
      codevalue -= OP_STARI - OP_STAR;
2439
      /* Fall through */
2440
0
      case OP_EXACT:
2441
0
      case OP_NOTEXACT:
2442
0
      count = current_state->count;  /* Number already matched */
2443
0
      if (clen > 0)
2444
0
        {
2445
0
        unsigned int otherd = NOTACHAR;
2446
0
        if (caseless)
2447
0
          {
2448
0
#ifdef SUPPORT_UTF
2449
0
          if (utf && d >= 128)
2450
0
            {
2451
0
#ifdef SUPPORT_UCP
2452
0
            otherd = UCD_OTHERCASE(d);
2453
0
#endif  /* SUPPORT_UCP */
2454
0
            }
2455
0
          else
2456
0
#endif  /* SUPPORT_UTF */
2457
0
          otherd = TABLE_GET(d, fcc, d);
2458
0
          }
2459
0
        if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
2460
0
          {
2461
0
          if (++count >= GET2(code, 1))
2462
0
            { ADD_NEW(state_offset + dlen + 1 + IMM2_SIZE, 0); }
2463
0
          else
2464
0
            { ADD_NEW(state_offset, count); }
2465
0
          }
2466
0
        }
2467
0
      break;
2468
2469
      /*-----------------------------------------------------------------*/
2470
0
      case OP_UPTOI:
2471
0
      case OP_MINUPTOI:
2472
0
      case OP_POSUPTOI:
2473
0
      case OP_NOTUPTOI:
2474
0
      case OP_NOTMINUPTOI:
2475
0
      case OP_NOTPOSUPTOI:
2476
0
      caseless = TRUE;
2477
0
      codevalue -= OP_STARI - OP_STAR;
2478
      /* Fall through */
2479
0
      case OP_UPTO:
2480
0
      case OP_MINUPTO:
2481
0
      case OP_POSUPTO:
2482
0
      case OP_NOTUPTO:
2483
0
      case OP_NOTMINUPTO:
2484
0
      case OP_NOTPOSUPTO:
2485
0
      ADD_ACTIVE(state_offset + dlen + 1 + IMM2_SIZE, 0);
2486
0
      count = current_state->count;  /* Number already matched */
2487
0
      if (clen > 0)
2488
0
        {
2489
0
        unsigned int otherd = NOTACHAR;
2490
0
        if (caseless)
2491
0
          {
2492
0
#ifdef SUPPORT_UTF
2493
0
          if (utf && d >= 128)
2494
0
            {
2495
0
#ifdef SUPPORT_UCP
2496
0
            otherd = UCD_OTHERCASE(d);
2497
0
#endif  /* SUPPORT_UCP */
2498
0
            }
2499
0
          else
2500
0
#endif  /* SUPPORT_UTF */
2501
0
          otherd = TABLE_GET(d, fcc, d);
2502
0
          }
2503
0
        if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR))
2504
0
          {
2505
0
          if (codevalue == OP_POSUPTO || codevalue == OP_NOTPOSUPTO)
2506
0
            {
2507
0
            active_count--;             /* Remove non-match possibility */
2508
0
            next_active_state--;
2509
0
            }
2510
0
          if (++count >= GET2(code, 1))
2511
0
            { ADD_NEW(state_offset + dlen + 1 + IMM2_SIZE, 0); }
2512
0
          else
2513
0
            { ADD_NEW(state_offset, count); }
2514
0
          }
2515
0
        }
2516
0
      break;
2517
2518
2519
/* ========================================================================== */
2520
      /* These are the class-handling opcodes */
2521
2522
0
      case OP_CLASS:
2523
0
      case OP_NCLASS:
2524
0
      case OP_XCLASS:
2525
0
        {
2526
0
        BOOL isinclass = FALSE;
2527
0
        int next_state_offset;
2528
0
        const pcre_uchar *ecode;
2529
2530
        /* For a simple class, there is always just a 32-byte table, and we
2531
        can set isinclass from it. */
2532
2533
0
        if (codevalue != OP_XCLASS)
2534
0
          {
2535
0
          ecode = code + 1 + (32 / sizeof(pcre_uchar));
2536
0
          if (clen > 0)
2537
0
            {
2538
0
            isinclass = (c > 255)? (codevalue == OP_NCLASS) :
2539
0
              ((((pcre_uint8 *)(code + 1))[c/8] & (1 << (c&7))) != 0);
2540
0
            }
2541
0
          }
2542
2543
        /* An extended class may have a table or a list of single characters,
2544
        ranges, or both, and it may be positive or negative. There's a
2545
        function that sorts all this out. */
2546
2547
0
        else
2548
0
         {
2549
0
         ecode = code + GET(code, 1);
2550
0
         if (clen > 0) isinclass = PRIV(xclass)(c, code + 1 + LINK_SIZE, utf);
2551
0
         }
2552
2553
        /* At this point, isinclass is set for all kinds of class, and ecode
2554
        points to the byte after the end of the class. If there is a
2555
        quantifier, this is where it will be. */
2556
2557
0
        next_state_offset = (int)(ecode - start_code);
2558
2559
0
        switch (*ecode)
2560
0
          {
2561
0
          case OP_CRSTAR:
2562
0
          case OP_CRMINSTAR:
2563
0
          ADD_ACTIVE(next_state_offset + 1, 0);
2564
0
          if (isinclass) { ADD_NEW(state_offset, 0); }
2565
0
          break;
2566
2567
0
          case OP_CRPLUS:
2568
0
          case OP_CRMINPLUS:
2569
0
          count = current_state->count;  /* Already matched */
2570
0
          if (count > 0) { ADD_ACTIVE(next_state_offset + 1, 0); }
2571
0
          if (isinclass) { count++; ADD_NEW(state_offset, count); }
2572
0
          break;
2573
2574
0
          case OP_CRQUERY:
2575
0
          case OP_CRMINQUERY:
2576
0
          ADD_ACTIVE(next_state_offset + 1, 0);
2577
0
          if (isinclass) { ADD_NEW(next_state_offset + 1, 0); }
2578
0
          break;
2579
2580
0
          case OP_CRRANGE:
2581
0
          case OP_CRMINRANGE:
2582
0
          count = current_state->count;  /* Already matched */
2583
0
          if (count >= GET2(ecode, 1))
2584
0
            { ADD_ACTIVE(next_state_offset + 1 + 2 * IMM2_SIZE, 0); }
2585
0
          if (isinclass)
2586
0
            {
2587
0
            int max = GET2(ecode, 1 + IMM2_SIZE);
2588
0
            if (++count >= max && max != 0)   /* Max 0 => no limit */
2589
0
              { ADD_NEW(next_state_offset + 1 + 2 * IMM2_SIZE, 0); }
2590
0
            else
2591
0
              { ADD_NEW(state_offset, count); }
2592
0
            }
2593
0
          break;
2594
2595
0
          default:
2596
0
          if (isinclass) { ADD_NEW(next_state_offset, 0); }
2597
0
          break;
2598
0
          }
2599
0
        }
2600
0
      break;
2601
2602
/* ========================================================================== */
2603
      /* These are the opcodes for fancy brackets of various kinds. We have
2604
      to use recursion in order to handle them. The "always failing" assertion
2605
      (?!) is optimised to OP_FAIL when compiling, so we have to support that,
2606
      though the other "backtracking verbs" are not supported. */
2607
2608
0
      case OP_FAIL:
2609
0
      forced_fail++;    /* Count FAILs for multiple states */
2610
0
      break;
2611
2612
0
      case OP_ASSERT:
2613
0
      case OP_ASSERT_NOT:
2614
0
      case OP_ASSERTBACK:
2615
0
      case OP_ASSERTBACK_NOT:
2616
0
        {
2617
0
        int rc;
2618
0
        int local_offsets[2];
2619
0
        int local_workspace[1000];
2620
0
        const pcre_uchar *endasscode = code + GET(code, 1);
2621
2622
0
        while (*endasscode == OP_ALT) endasscode += GET(endasscode, 1);
2623
2624
0
        rc = internal_dfa_exec(
2625
0
          md,                                   /* static match data */
2626
0
          code,                                 /* this subexpression's code */
2627
0
          ptr,                                  /* where we currently are */
2628
0
          (int)(ptr - start_subject),           /* start offset */
2629
0
          local_offsets,                        /* offset vector */
2630
0
          sizeof(local_offsets)/sizeof(int),    /* size of same */
2631
0
          local_workspace,                      /* workspace vector */
2632
0
          sizeof(local_workspace)/sizeof(int),  /* size of same */
2633
0
          rlevel);                              /* function recursion level */
2634
2635
0
        if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2636
0
        if ((rc >= 0) == (codevalue == OP_ASSERT || codevalue == OP_ASSERTBACK))
2637
0
            { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); }
2638
0
        }
2639
0
      break;
2640
2641
      /*-----------------------------------------------------------------*/
2642
0
      case OP_COND:
2643
0
      case OP_SCOND:
2644
0
        {
2645
0
        int local_offsets[1000];
2646
0
        int local_workspace[1000];
2647
0
        int codelink = GET(code, 1);
2648
0
        int condcode;
2649
2650
        /* Because of the way auto-callout works during compile, a callout item
2651
        is inserted between OP_COND and an assertion condition. This does not
2652
        happen for the other conditions. */
2653
2654
0
        if (code[LINK_SIZE+1] == OP_CALLOUT)
2655
0
          {
2656
0
          rrc = 0;
2657
0
          if (PUBL(callout) != NULL)
2658
0
            {
2659
0
            PUBL(callout_block) cb;
2660
0
            cb.version          = 1;   /* Version 1 of the callout block */
2661
0
            cb.callout_number   = code[LINK_SIZE+2];
2662
0
            cb.offset_vector    = offsets;
2663
0
#ifdef COMPILE_PCRE8
2664
0
            cb.subject          = (PCRE_SPTR)start_subject;
2665
#else
2666
            cb.subject          = (PCRE_SPTR16)start_subject;
2667
#endif
2668
0
            cb.subject_length   = (int)(end_subject - start_subject);
2669
0
            cb.start_match      = (int)(current_subject - start_subject);
2670
0
            cb.current_position = (int)(ptr - start_subject);
2671
0
            cb.pattern_position = GET(code, LINK_SIZE + 3);
2672
0
            cb.next_item_length = GET(code, 3 + 2*LINK_SIZE);
2673
0
            cb.capture_top      = 1;
2674
0
            cb.capture_last     = -1;
2675
0
            cb.callout_data     = md->callout_data;
2676
0
            cb.mark             = NULL;   /* No (*MARK) support */
2677
0
            if ((rrc = (*PUBL(callout))(&cb)) < 0) return rrc;   /* Abandon */
2678
0
            }
2679
0
          if (rrc > 0) break;                      /* Fail this thread */
2680
0
          code += PRIV(OP_lengths)[OP_CALLOUT];    /* Skip callout data */
2681
0
          }
2682
2683
0
        condcode = code[LINK_SIZE+1];
2684
2685
        /* Back reference conditions are not supported */
2686
2687
0
        if (condcode == OP_CREF || condcode == OP_NCREF)
2688
0
          return PCRE_ERROR_DFA_UCOND;
2689
2690
        /* The DEFINE condition is always false */
2691
2692
0
        if (condcode == OP_DEF)
2693
0
          { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2694
2695
        /* The only supported version of OP_RREF is for the value RREF_ANY,
2696
        which means "test if in any recursion". We can't test for specifically
2697
        recursed groups. */
2698
2699
0
        else if (condcode == OP_RREF || condcode == OP_NRREF)
2700
0
          {
2701
0
          int value = GET2(code, LINK_SIZE + 2);
2702
0
          if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND;
2703
0
          if (md->recursive != NULL)
2704
0
            { ADD_ACTIVE(state_offset + LINK_SIZE + 2 + IMM2_SIZE, 0); }
2705
0
          else { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2706
0
          }
2707
2708
        /* Otherwise, the condition is an assertion */
2709
2710
0
        else
2711
0
          {
2712
0
          int rc;
2713
0
          const pcre_uchar *asscode = code + LINK_SIZE + 1;
2714
0
          const pcre_uchar *endasscode = asscode + GET(asscode, 1);
2715
2716
0
          while (*endasscode == OP_ALT) endasscode += GET(endasscode, 1);
2717
2718
0
          rc = internal_dfa_exec(
2719
0
            md,                                   /* fixed match data */
2720
0
            asscode,                              /* this subexpression's code */
2721
0
            ptr,                                  /* where we currently are */
2722
0
            (int)(ptr - start_subject),           /* start offset */
2723
0
            local_offsets,                        /* offset vector */
2724
0
            sizeof(local_offsets)/sizeof(int),    /* size of same */
2725
0
            local_workspace,                      /* workspace vector */
2726
0
            sizeof(local_workspace)/sizeof(int),  /* size of same */
2727
0
            rlevel);                              /* function recursion level */
2728
2729
0
          if (rc == PCRE_ERROR_DFA_UITEM) return rc;
2730
0
          if ((rc >= 0) ==
2731
0
                (condcode == OP_ASSERT || condcode == OP_ASSERTBACK))
2732
0
            { ADD_ACTIVE((int)(endasscode + LINK_SIZE + 1 - start_code), 0); }
2733
0
          else
2734
0
            { ADD_ACTIVE(state_offset + codelink + LINK_SIZE + 1, 0); }
2735
0
          }
2736
0
        }
2737
0
      break;
2738
2739
      /*-----------------------------------------------------------------*/
2740
0
      case OP_RECURSE:
2741
0
        {
2742
0
        dfa_recursion_info *ri;
2743
0
        int local_offsets[1000];
2744
0
        int local_workspace[1000];
2745
0
        const pcre_uchar *callpat = start_code + GET(code, 1);
2746
0
        int recno = (callpat == md->start_code)? 0 :
2747
0
          GET2(callpat, 1 + LINK_SIZE);
2748
0
        int rc;
2749
2750
0
        DPRINTF(("%.*sStarting regex recursion\n", rlevel*2-2, SP));
2751
2752
        /* Check for repeating a recursion without advancing the subject
2753
        pointer. This should catch convoluted mutual recursions. (Some simple
2754
        cases are caught at compile time.) */
2755
2756
0
        for (ri = md->recursive; ri != NULL; ri = ri->prevrec)
2757
0
          if (recno == ri->group_num && ptr == ri->subject_position)
2758
0
            return PCRE_ERROR_RECURSELOOP;
2759
2760
        /* Remember this recursion and where we started it so as to
2761
        catch infinite loops. */
2762
2763
0
        new_recursive.group_num = recno;
2764
0
        new_recursive.subject_position = ptr;
2765
0
        new_recursive.prevrec = md->recursive;
2766
0
        md->recursive = &new_recursive;
2767
2768
0
        rc = internal_dfa_exec(
2769
0
          md,                                   /* fixed match data */
2770
0
          callpat,                              /* this subexpression's code */
2771
0
          ptr,                                  /* where we currently are */
2772
0
          (int)(ptr - start_subject),           /* start offset */
2773
0
          local_offsets,                        /* offset vector */
2774
0
          sizeof(local_offsets)/sizeof(int),    /* size of same */
2775
0
          local_workspace,                      /* workspace vector */
2776
0
          sizeof(local_workspace)/sizeof(int),  /* size of same */
2777
0
          rlevel);                              /* function recursion level */
2778
2779
0
        md->recursive = new_recursive.prevrec;  /* Done this recursion */
2780
2781
0
        DPRINTF(("%.*sReturn from regex recursion: rc=%d\n", rlevel*2-2, SP,
2782
0
          rc));
2783
2784
        /* Ran out of internal offsets */
2785
2786
0
        if (rc == 0) return PCRE_ERROR_DFA_RECURSE;
2787
2788
        /* For each successful matched substring, set up the next state with a
2789
        count of characters to skip before trying it. Note that the count is in
2790
        characters, not bytes. */
2791
2792
0
        if (rc > 0)
2793
0
          {
2794
0
          for (rc = rc*2 - 2; rc >= 0; rc -= 2)
2795
0
            {
2796
0
            int charcount = local_offsets[rc+1] - local_offsets[rc];
2797
0
#ifdef SUPPORT_UTF
2798
0
            if (utf)
2799
0
              {
2800
0
              const pcre_uchar *p = start_subject + local_offsets[rc];
2801
0
              const pcre_uchar *pp = start_subject + local_offsets[rc+1];
2802
0
              while (p < pp) if (NOT_FIRSTCHAR(*p++)) charcount--;
2803
0
              }
2804
0
#endif
2805
0
            if (charcount > 0)
2806
0
              {
2807
0
              ADD_NEW_DATA(-(state_offset + LINK_SIZE + 1), 0, (charcount - 1));
2808
0
              }
2809
0
            else
2810
0
              {
2811
0
              ADD_ACTIVE(state_offset + LINK_SIZE + 1, 0);
2812
0
              }
2813
0
            }
2814
0
          }
2815
0
        else if (rc != PCRE_ERROR_NOMATCH) return rc;
2816
0
        }
2817
0
      break;
2818
2819
      /*-----------------------------------------------------------------*/
2820
0
      case OP_BRAPOS:
2821
0
      case OP_SBRAPOS:
2822
0
      case OP_CBRAPOS:
2823
0
      case OP_SCBRAPOS:
2824
0
      case OP_BRAPOSZERO:
2825
0
        {
2826
0
        int charcount, matched_count;
2827
0
        const pcre_uchar *local_ptr = ptr;
2828
0
        BOOL allow_zero;
2829
2830
0
        if (codevalue == OP_BRAPOSZERO)
2831
0
          {
2832
0
          allow_zero = TRUE;
2833
0
          codevalue = *(++code);  /* Codevalue will be one of above BRAs */
2834
0
          }
2835
0
        else allow_zero = FALSE;
2836
2837
        /* Loop to match the subpattern as many times as possible as if it were
2838
        a complete pattern. */
2839
2840
0
        for (matched_count = 0;; matched_count++)
2841
0
          {
2842
0
          int local_offsets[2];
2843
0
          int local_workspace[1000];
2844
2845
0
          int rc = internal_dfa_exec(
2846
0
            md,                                   /* fixed match data */
2847
0
            code,                                 /* this subexpression's code */
2848
0
            local_ptr,                            /* where we currently are */
2849
0
            (int)(ptr - start_subject),           /* start offset */
2850
0
            local_offsets,                        /* offset vector */
2851
0
            sizeof(local_offsets)/sizeof(int),    /* size of same */
2852
0
            local_workspace,                      /* workspace vector */
2853
0
            sizeof(local_workspace)/sizeof(int),  /* size of same */
2854
0
            rlevel);                              /* function recursion level */
2855
2856
          /* Failed to match */
2857
2858
0
          if (rc < 0)
2859
0
            {
2860
0
            if (rc != PCRE_ERROR_NOMATCH) return rc;
2861
0
            break;
2862
0
            }
2863
2864
          /* Matched: break the loop if zero characters matched. */
2865
2866
0
          charcount = local_offsets[1] - local_offsets[0];
2867
0
          if (charcount == 0) break;
2868
0
          local_ptr += charcount;    /* Advance temporary position ptr */
2869
0
          }
2870
2871
        /* At this point we have matched the subpattern matched_count
2872
        times, and local_ptr is pointing to the character after the end of the
2873
        last match. */
2874
2875
0
        if (matched_count > 0 || allow_zero)
2876
0
          {
2877
0
          const pcre_uchar *end_subpattern = code;
2878
0
          int next_state_offset;
2879
2880
0
          do { end_subpattern += GET(end_subpattern, 1); }
2881
0
            while (*end_subpattern == OP_ALT);
2882
0
          next_state_offset =
2883
0
            (int)(end_subpattern - start_code + LINK_SIZE + 1);
2884
2885
          /* Optimization: if there are no more active states, and there
2886
          are no new states yet set up, then skip over the subject string
2887
          right here, to save looping. Otherwise, set up the new state to swing
2888
          into action when the end of the matched substring is reached. */
2889
2890
0
          if (i + 1 >= active_count && new_count == 0)
2891
0
            {
2892
0
            ptr = local_ptr;
2893
0
            clen = 0;
2894
0
            ADD_NEW(next_state_offset, 0);
2895
0
            }
2896
0
          else
2897
0
            {
2898
0
            const pcre_uchar *p = ptr;
2899
0
            const pcre_uchar *pp = local_ptr;
2900
0
            charcount = (int)(pp - p);
2901
0
#ifdef SUPPORT_UTF
2902
0
            if (utf) while (p < pp) if (NOT_FIRSTCHAR(*p++)) charcount--;
2903
0
#endif
2904
0
            ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1));
2905
0
            }
2906
0
          }
2907
0
        }
2908
0
      break;
2909
2910
      /*-----------------------------------------------------------------*/
2911
0
      case OP_ONCE:
2912
0
      case OP_ONCE_NC:
2913
0
        {
2914
0
        int local_offsets[2];
2915
0
        int local_workspace[1000];
2916
2917
0
        int rc = internal_dfa_exec(
2918
0
          md,                                   /* fixed match data */
2919
0
          code,                                 /* this subexpression's code */
2920
0
          ptr,                                  /* where we currently are */
2921
0
          (int)(ptr - start_subject),           /* start offset */
2922
0
          local_offsets,                        /* offset vector */
2923
0
          sizeof(local_offsets)/sizeof(int),    /* size of same */
2924
0
          local_workspace,                      /* workspace vector */
2925
0
          sizeof(local_workspace)/sizeof(int),  /* size of same */
2926
0
          rlevel);                              /* function recursion level */
2927
2928
0
        if (rc >= 0)
2929
0
          {
2930
0
          const pcre_uchar *end_subpattern = code;
2931
0
          int charcount = local_offsets[1] - local_offsets[0];
2932
0
          int next_state_offset, repeat_state_offset;
2933
2934
0
          do { end_subpattern += GET(end_subpattern, 1); }
2935
0
            while (*end_subpattern == OP_ALT);
2936
0
          next_state_offset =
2937
0
            (int)(end_subpattern - start_code + LINK_SIZE + 1);
2938
2939
          /* If the end of this subpattern is KETRMAX or KETRMIN, we must
2940
          arrange for the repeat state also to be added to the relevant list.
2941
          Calculate the offset, or set -1 for no repeat. */
2942
2943
0
          repeat_state_offset = (*end_subpattern == OP_KETRMAX ||
2944
0
                                 *end_subpattern == OP_KETRMIN)?
2945
0
            (int)(end_subpattern - start_code - GET(end_subpattern, 1)) : -1;
2946
2947
          /* If we have matched an empty string, add the next state at the
2948
          current character pointer. This is important so that the duplicate
2949
          checking kicks in, which is what breaks infinite loops that match an
2950
          empty string. */
2951
2952
0
          if (charcount == 0)
2953
0
            {
2954
0
            ADD_ACTIVE(next_state_offset, 0);
2955
0
            }
2956
2957
          /* Optimization: if there are no more active states, and there
2958
          are no new states yet set up, then skip over the subject string
2959
          right here, to save looping. Otherwise, set up the new state to swing
2960
          into action when the end of the matched substring is reached. */
2961
2962
0
          else if (i + 1 >= active_count && new_count == 0)
2963
0
            {
2964
0
            ptr += charcount;
2965
0
            clen = 0;
2966
0
            ADD_NEW(next_state_offset, 0);
2967
2968
            /* If we are adding a repeat state at the new character position,
2969
            we must fudge things so that it is the only current state.
2970
            Otherwise, it might be a duplicate of one we processed before, and
2971
            that would cause it to be skipped. */
2972
2973
0
            if (repeat_state_offset >= 0)
2974
0
              {
2975
0
              next_active_state = active_states;
2976
0
              active_count = 0;
2977
0
              i = -1;
2978
0
              ADD_ACTIVE(repeat_state_offset, 0);
2979
0
              }
2980
0
            }
2981
0
          else
2982
0
            {
2983
0
#ifdef SUPPORT_UTF
2984
0
            if (utf)
2985
0
              {
2986
0
              const pcre_uchar *p = start_subject + local_offsets[0];
2987
0
              const pcre_uchar *pp = start_subject + local_offsets[1];
2988
0
              while (p < pp) if (NOT_FIRSTCHAR(*p++)) charcount--;
2989
0
              }
2990
0
#endif
2991
0
            ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1));
2992
0
            if (repeat_state_offset >= 0)
2993
0
              { ADD_NEW_DATA(-repeat_state_offset, 0, (charcount - 1)); }
2994
0
            }
2995
0
          }
2996
0
        else if (rc != PCRE_ERROR_NOMATCH) return rc;
2997
0
        }
2998
0
      break;
2999
3000
3001
/* ========================================================================== */
3002
      /* Handle callouts */
3003
3004
0
      case OP_CALLOUT:
3005
0
      rrc = 0;
3006
0
      if (PUBL(callout) != NULL)
3007
0
        {
3008
0
        PUBL(callout_block) cb;
3009
0
        cb.version          = 1;   /* Version 1 of the callout block */
3010
0
        cb.callout_number   = code[1];
3011
0
        cb.offset_vector    = offsets;
3012
0
#ifdef COMPILE_PCRE8
3013
0
        cb.subject          = (PCRE_SPTR)start_subject;
3014
#else
3015
        cb.subject          = (PCRE_SPTR16)start_subject;
3016
#endif
3017
0
        cb.subject_length   = (int)(end_subject - start_subject);
3018
0
        cb.start_match      = (int)(current_subject - start_subject);
3019
0
        cb.current_position = (int)(ptr - start_subject);
3020
0
        cb.pattern_position = GET(code, 2);
3021
0
        cb.next_item_length = GET(code, 2 + LINK_SIZE);
3022
0
        cb.capture_top      = 1;
3023
0
        cb.capture_last     = -1;
3024
0
        cb.callout_data     = md->callout_data;
3025
0
        cb.mark             = NULL;   /* No (*MARK) support */
3026
0
        if ((rrc = (*PUBL(callout))(&cb)) < 0) return rrc;   /* Abandon */
3027
0
        }
3028
0
      if (rrc == 0)
3029
0
        { ADD_ACTIVE(state_offset + PRIV(OP_lengths)[OP_CALLOUT], 0); }
3030
0
      break;
3031
3032
3033
/* ========================================================================== */
3034
0
      default:        /* Unsupported opcode */
3035
0
      return PCRE_ERROR_DFA_UITEM;
3036
0
      }
3037
3038
0
    NEXT_ACTIVE_STATE: continue;
3039
3040
0
    }      /* End of loop scanning active states */
3041
3042
  /* We have finished the processing at the current subject character. If no
3043
  new states have been set for the next character, we have found all the
3044
  matches that we are going to find. If we are at the top level and partial
3045
  matching has been requested, check for appropriate conditions.
3046
3047
  The "forced_ fail" variable counts the number of (*F) encountered for the
3048
  character. If it is equal to the original active_count (saved in
3049
  workspace[1]) it means that (*F) was found on every active state. In this
3050
  case we don't want to give a partial match.
3051
3052
  The "could_continue" variable is true if a state could have continued but
3053
  for the fact that the end of the subject was reached. */
3054
3055
0
  if (new_count <= 0)
3056
0
    {
3057
0
    if (rlevel == 1 &&                               /* Top level, and */
3058
0
        could_continue &&                            /* Some could go on, and */
3059
0
        forced_fail != workspace[1] &&               /* Not all forced fail & */
3060
0
        (                                            /* either... */
3061
0
        (md->moptions & PCRE_PARTIAL_HARD) != 0      /* Hard partial */
3062
0
        ||                                           /* or... */
3063
0
        ((md->moptions & PCRE_PARTIAL_SOFT) != 0 &&  /* Soft partial and */
3064
0
         match_count < 0)                            /* no matches */
3065
0
        ) &&                                         /* And... */
3066
0
        (
3067
0
        partial_newline ||                           /* Either partial NL */
3068
0
          (                                          /* or ... */
3069
0
          ptr >= end_subject &&                /* End of subject and */
3070
0
          ptr > md->start_used_ptr)            /* Inspected non-empty string */
3071
0
          )
3072
0
        )
3073
0
      {
3074
0
      if (offsetcount >= 2)
3075
0
        {
3076
0
        offsets[0] = (int)(md->start_used_ptr - start_subject);
3077
0
        offsets[1] = (int)(end_subject - start_subject);
3078
0
        }
3079
0
      match_count = PCRE_ERROR_PARTIAL;
3080
0
      }
3081
3082
0
    DPRINTF(("%.*sEnd of internal_dfa_exec %d: returning %d\n"
3083
0
      "%.*s---------------------\n\n", rlevel*2-2, SP, rlevel, match_count,
3084
0
      rlevel*2-2, SP));
3085
0
    break;        /* In effect, "return", but see the comment below */
3086
0
    }
3087
3088
  /* One or more states are active for the next character. */
3089
3090
0
  ptr += clen;    /* Advance to next subject character */
3091
0
  }               /* Loop to move along the subject string */
3092
3093
/* Control gets here from "break" a few lines above. We do it this way because
3094
if we use "return" above, we have compiler trouble. Some compilers warn if
3095
there's nothing here because they think the function doesn't return a value. On
3096
the other hand, if we put a dummy statement here, some more clever compilers
3097
complain that it can't be reached. Sigh. */
3098
3099
0
return match_count;
3100
0
}
3101
3102
3103
3104
3105
/*************************************************
3106
*    Execute a Regular Expression - DFA engine   *
3107
*************************************************/
3108
3109
/* This external function applies a compiled re to a subject string using a DFA
3110
engine. This function calls the internal function multiple times if the pattern
3111
is not anchored.
3112
3113
Arguments:
3114
  argument_re     points to the compiled expression
3115
  extra_data      points to extra data or is NULL
3116
  subject         points to the subject string
3117
  length          length of subject string (may contain binary zeros)
3118
  start_offset    where to start in the subject string
3119
  options         option bits
3120
  offsets         vector of match offsets
3121
  offsetcount     size of same
3122
  workspace       workspace vector
3123
  wscount         size of same
3124
3125
Returns:          > 0 => number of match offset pairs placed in offsets
3126
                  = 0 => offsets overflowed; longest matches are present
3127
                   -1 => failed to match
3128
                 < -1 => some kind of unexpected problem
3129
*/
3130
3131
#ifdef COMPILE_PCRE8
3132
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
3133
pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data,
3134
  const char *subject, int length, int start_offset, int options, int *offsets,
3135
  int offsetcount, int *workspace, int wscount)
3136
#else
3137
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
3138
pcre16_dfa_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,
3139
  PCRE_SPTR16 subject, int length, int start_offset, int options, int *offsets,
3140
  int offsetcount, int *workspace, int wscount)
3141
#endif
3142
0
{
3143
0
REAL_PCRE *re = (REAL_PCRE *)argument_re;
3144
0
dfa_match_data match_block;
3145
0
dfa_match_data *md = &match_block;
3146
0
BOOL utf, anchored, startline, firstline;
3147
0
const pcre_uchar *current_subject, *end_subject;
3148
0
const pcre_study_data *study = NULL;
3149
3150
0
const pcre_uchar *req_char_ptr;
3151
0
const pcre_uint8 *start_bits = NULL;
3152
0
BOOL has_first_char = FALSE;
3153
0
BOOL has_req_char = FALSE;
3154
0
pcre_uchar first_char = 0;
3155
0
pcre_uchar first_char2 = 0;
3156
0
pcre_uchar req_char = 0;
3157
0
pcre_uchar req_char2 = 0;
3158
0
int newline;
3159
3160
/* Plausibility checks */
3161
3162
0
if ((options & ~PUBLIC_DFA_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
3163
0
if (re == NULL || subject == NULL || workspace == NULL ||
3164
0
   (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
3165
0
if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
3166
0
if (wscount < 20) return PCRE_ERROR_DFA_WSSIZE;
3167
0
if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
3168
3169
/* Check that the first field in the block is the magic number. If it is not,
3170
return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to
3171
REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which
3172
means that the pattern is likely compiled with different endianness. */
3173
3174
0
if (re->magic_number != MAGIC_NUMBER)
3175
0
  return re->magic_number == REVERSED_MAGIC_NUMBER?
3176
0
    PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC;
3177
0
if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
3178
3179
/* If restarting after a partial match, do some sanity checks on the contents
3180
of the workspace. */
3181
3182
0
if ((options & PCRE_DFA_RESTART) != 0)
3183
0
  {
3184
0
  if ((workspace[0] & (-2)) != 0 || workspace[1] < 1 ||
3185
0
    workspace[1] > (wscount - 2)/INTS_PER_STATEBLOCK)
3186
0
      return PCRE_ERROR_DFA_BADRESTART;
3187
0
  }
3188
3189
/* Set up study, callout, and table data */
3190
3191
0
md->tables = re->tables;
3192
0
md->callout_data = NULL;
3193
3194
0
if (extra_data != NULL)
3195
0
  {
3196
0
  unsigned int flags = extra_data->flags;
3197
0
  if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
3198
0
    study = (const pcre_study_data *)extra_data->study_data;
3199
0
  if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0) return PCRE_ERROR_DFA_UMLIMIT;
3200
0
  if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)
3201
0
    return PCRE_ERROR_DFA_UMLIMIT;
3202
0
  if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
3203
0
    md->callout_data = extra_data->callout_data;
3204
0
  if ((flags & PCRE_EXTRA_TABLES) != 0)
3205
0
    md->tables = extra_data->tables;
3206
0
  }
3207
3208
/* Set some local values */
3209
3210
0
current_subject = (const pcre_uchar *)subject + start_offset;
3211
0
end_subject = (const pcre_uchar *)subject + length;
3212
0
req_char_ptr = current_subject - 1;
3213
3214
0
#ifdef SUPPORT_UTF
3215
/* PCRE_UTF16 has the same value as PCRE_UTF8. */
3216
0
utf = (re->options & PCRE_UTF8) != 0;
3217
#else
3218
utf = FALSE;
3219
#endif
3220
3221
0
anchored = (options & (PCRE_ANCHORED|PCRE_DFA_RESTART)) != 0 ||
3222
0
  (re->options & PCRE_ANCHORED) != 0;
3223
3224
/* The remaining fixed data for passing around. */
3225
3226
0
md->start_code = (const pcre_uchar *)argument_re +
3227
0
    re->name_table_offset + re->name_count * re->name_entry_size;
3228
0
md->start_subject = (const pcre_uchar *)subject;
3229
0
md->end_subject = end_subject;
3230
0
md->start_offset = start_offset;
3231
0
md->moptions = options;
3232
0
md->poptions = re->options;
3233
3234
/* If the BSR option is not set at match time, copy what was set
3235
at compile time. */
3236
3237
0
if ((md->moptions & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) == 0)
3238
0
  {
3239
0
  if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
3240
0
    md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE);
3241
#ifdef BSR_ANYCRLF
3242
  else md->moptions |= PCRE_BSR_ANYCRLF;
3243
#endif
3244
0
  }
3245
3246
/* Handle different types of newline. The three bits give eight cases. If
3247
nothing is set at run time, whatever was used at compile time applies. */
3248
3249
0
switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &
3250
0
         PCRE_NEWLINE_BITS)
3251
0
  {
3252
0
  case 0: newline = NEWLINE; break;   /* Compile-time default */
3253
0
  case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
3254
0
  case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
3255
0
  case PCRE_NEWLINE_CR+
3256
0
       PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
3257
0
  case PCRE_NEWLINE_ANY: newline = -1; break;
3258
0
  case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
3259
0
  default: return PCRE_ERROR_BADNEWLINE;
3260
0
  }
3261
3262
0
if (newline == -2)
3263
0
  {
3264
0
  md->nltype = NLTYPE_ANYCRLF;
3265
0
  }
3266
0
else if (newline < 0)
3267
0
  {
3268
0
  md->nltype = NLTYPE_ANY;
3269
0
  }
3270
0
else
3271
0
  {
3272
0
  md->nltype = NLTYPE_FIXED;
3273
0
  if (newline > 255)
3274
0
    {
3275
0
    md->nllen = 2;
3276
0
    md->nl[0] = (newline >> 8) & 255;
3277
0
    md->nl[1] = newline & 255;
3278
0
    }
3279
0
  else
3280
0
    {
3281
0
    md->nllen = 1;
3282
0
    md->nl[0] = newline;
3283
0
    }
3284
0
  }
3285
3286
/* Check a UTF-8 string if required. Unfortunately there's no way of passing
3287
back the character offset. */
3288
3289
0
#ifdef SUPPORT_UTF
3290
0
if (utf && (options & PCRE_NO_UTF8_CHECK) == 0)
3291
0
  {
3292
0
  int erroroffset;
3293
0
  int errorcode = PRIV(valid_utf)((pcre_uchar *)subject, length, &erroroffset);
3294
0
  if (errorcode != 0)
3295
0
    {
3296
0
    if (offsetcount >= 2)
3297
0
      {
3298
0
      offsets[0] = erroroffset;
3299
0
      offsets[1] = errorcode;
3300
0
      }
3301
0
    return (errorcode <= PCRE_UTF8_ERR5 && (options & PCRE_PARTIAL_HARD) != 0)?
3302
0
      PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
3303
0
    }
3304
0
  if (start_offset > 0 && start_offset < length &&
3305
0
        NOT_FIRSTCHAR(((PCRE_PUCHAR)subject)[start_offset]))
3306
0
    return PCRE_ERROR_BADUTF8_OFFSET;
3307
0
  }
3308
0
#endif
3309
3310
/* If the exec call supplied NULL for tables, use the inbuilt ones. This
3311
is a feature that makes it possible to save compiled regex and re-use them
3312
in other programs later. */
3313
3314
0
if (md->tables == NULL) md->tables = PRIV(default_tables);
3315
3316
/* The "must be at the start of a line" flags are used in a loop when finding
3317
where to start. */
3318
3319
0
startline = (re->flags & PCRE_STARTLINE) != 0;
3320
0
firstline = (re->options & PCRE_FIRSTLINE) != 0;
3321
3322
/* Set up the first character to match, if available. The first_byte value is
3323
never set for an anchored regular expression, but the anchoring may be forced
3324
at run time, so we have to test for anchoring. The first char may be unset for
3325
an unanchored pattern, of course. If there's no first char and the pattern was
3326
studied, there may be a bitmap of possible first characters. */
3327
3328
0
if (!anchored)
3329
0
  {
3330
0
  if ((re->flags & PCRE_FIRSTSET) != 0)
3331
0
    {
3332
0
    has_first_char = TRUE;
3333
0
    first_char = first_char2 = (pcre_uchar)(re->first_char);
3334
0
    if ((re->flags & PCRE_FCH_CASELESS) != 0)
3335
0
      {
3336
0
      first_char2 = TABLE_GET(first_char, md->tables + fcc_offset, first_char);
3337
#if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3338
      if (utf && first_char > 127)
3339
        first_char2 = UCD_OTHERCASE(first_char);
3340
#endif
3341
0
      }
3342
0
    }
3343
0
  else
3344
0
    {
3345
0
    if (!startline && study != NULL &&
3346
0
         (study->flags & PCRE_STUDY_MAPPED) != 0)
3347
0
      start_bits = study->start_bits;
3348
0
    }
3349
0
  }
3350
3351
/* For anchored or unanchored matches, there may be a "last known required
3352
character" set. */
3353
3354
0
if ((re->flags & PCRE_REQCHSET) != 0)
3355
0
  {
3356
0
  has_req_char = TRUE;
3357
0
  req_char = req_char2 = (pcre_uchar)(re->req_char);
3358
0
  if ((re->flags & PCRE_RCH_CASELESS) != 0)
3359
0
    {
3360
0
    req_char2 = TABLE_GET(req_char, md->tables + fcc_offset, req_char);
3361
#if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3362
    if (utf && req_char > 127)
3363
      req_char2 = UCD_OTHERCASE(req_char);
3364
#endif
3365
0
    }
3366
0
  }
3367
3368
/* Call the main matching function, looping for a non-anchored regex after a
3369
failed match. If not restarting, perform certain optimizations at the start of
3370
a match. */
3371
3372
0
for (;;)
3373
0
  {
3374
0
  int rc;
3375
3376
0
  if ((options & PCRE_DFA_RESTART) == 0)
3377
0
    {
3378
0
    const pcre_uchar *save_end_subject = end_subject;
3379
3380
    /* If firstline is TRUE, the start of the match is constrained to the first
3381
    line of a multiline string. Implement this by temporarily adjusting
3382
    end_subject so that we stop scanning at a newline. If the match fails at
3383
    the newline, later code breaks this loop. */
3384
3385
0
    if (firstline)
3386
0
      {
3387
0
      PCRE_PUCHAR t = current_subject;
3388
0
#ifdef SUPPORT_UTF
3389
0
      if (utf)
3390
0
        {
3391
0
        while (t < md->end_subject && !IS_NEWLINE(t))
3392
0
          {
3393
0
          t++;
3394
0
          ACROSSCHAR(t < end_subject, *t, t++);
3395
0
          }
3396
0
        }
3397
0
      else
3398
0
#endif
3399
0
      while (t < md->end_subject && !IS_NEWLINE(t)) t++;
3400
0
      end_subject = t;
3401
0
      }
3402
3403
    /* There are some optimizations that avoid running the match if a known
3404
    starting point is not found. However, there is an option that disables
3405
    these, for testing and for ensuring that all callouts do actually occur.
3406
    The option can be set in the regex by (*NO_START_OPT) or passed in
3407
    match-time options. */
3408
3409
0
    if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0)
3410
0
      {
3411
      /* Advance to a known first char. */
3412
3413
0
      if (has_first_char)
3414
0
        {
3415
0
        if (first_char != first_char2)
3416
0
          while (current_subject < end_subject &&
3417
0
              *current_subject != first_char && *current_subject != first_char2)
3418
0
            current_subject++;
3419
0
        else
3420
0
          while (current_subject < end_subject &&
3421
0
                 *current_subject != first_char)
3422
0
            current_subject++;
3423
0
        }
3424
3425
      /* Or to just after a linebreak for a multiline match if possible */
3426
3427
0
      else if (startline)
3428
0
        {
3429
0
        if (current_subject > md->start_subject + start_offset)
3430
0
          {
3431
0
#ifdef SUPPORT_UTF
3432
0
          if (utf)
3433
0
            {
3434
0
            while (current_subject < end_subject &&
3435
0
                   !WAS_NEWLINE(current_subject))
3436
0
              {
3437
0
              current_subject++;
3438
0
              ACROSSCHAR(current_subject < end_subject, *current_subject,
3439
0
                current_subject++);
3440
0
              }
3441
0
            }
3442
0
          else
3443
0
#endif
3444
0
          while (current_subject < end_subject && !WAS_NEWLINE(current_subject))
3445
0
            current_subject++;
3446
3447
          /* If we have just passed a CR and the newline option is ANY or
3448
          ANYCRLF, and we are now at a LF, advance the match position by one
3449
          more character. */
3450
3451
0
          if (current_subject[-1] == CHAR_CR &&
3452
0
               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
3453
0
               current_subject < end_subject &&
3454
0
               *current_subject == CHAR_NL)
3455
0
            current_subject++;
3456
0
          }
3457
0
        }
3458
3459
      /* Or to a non-unique first char after study */
3460
3461
0
      else if (start_bits != NULL)
3462
0
        {
3463
0
        while (current_subject < end_subject)
3464
0
          {
3465
0
          unsigned int c = *current_subject;
3466
#ifndef COMPILE_PCRE8
3467
          if (c > 255) c = 255;
3468
#endif
3469
0
          if ((start_bits[c/8] & (1 << (c&7))) == 0)
3470
0
            {
3471
0
            current_subject++;
3472
0
#if defined SUPPORT_UTF && defined COMPILE_PCRE8
3473
            /* In non 8-bit mode, the iteration will stop for
3474
            characters > 255 at the beginning or not stop at all. */
3475
0
            if (utf)
3476
0
              ACROSSCHAR(current_subject < end_subject, *current_subject,
3477
0
                current_subject++);
3478
0
#endif
3479
0
            }
3480
0
          else break;
3481
0
          }
3482
0
        }
3483
0
      }
3484
3485
    /* Restore fudged end_subject */
3486
3487
0
    end_subject = save_end_subject;
3488
3489
    /* The following two optimizations are disabled for partial matching or if
3490
    disabling is explicitly requested (and of course, by the test above, this
3491
    code is not obeyed when restarting after a partial match). */
3492
3493
0
    if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0 &&
3494
0
        (options & (PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT)) == 0)
3495
0
      {
3496
      /* If the pattern was studied, a minimum subject length may be set. This
3497
      is a lower bound; no actual string of that length may actually match the
3498
      pattern. Although the value is, strictly, in characters, we treat it as
3499
      bytes to avoid spending too much time in this optimization. */
3500
3501
0
      if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 &&
3502
0
          (pcre_uint32)(end_subject - current_subject) < study->minlength)
3503
0
        return PCRE_ERROR_NOMATCH;
3504
3505
      /* If req_char is set, we know that that character must appear in the
3506
      subject for the match to succeed. If the first character is set, req_char
3507
      must be later in the subject; otherwise the test starts at the match
3508
      point. This optimization can save a huge amount of work in patterns with
3509
      nested unlimited repeats that aren't going to match. Writing separate
3510
      code for cased/caseless versions makes it go faster, as does using an
3511
      autoincrement and backing off on a match.
3512
3513
      HOWEVER: when the subject string is very, very long, searching to its end
3514
      can take a long time, and give bad performance on quite ordinary
3515
      patterns. This showed up when somebody was matching /^C/ on a 32-megabyte
3516
      string... so we don't do this when the string is sufficiently long. */
3517
3518
0
      if (has_req_char && end_subject - current_subject < REQ_BYTE_MAX)
3519
0
        {
3520
0
        PCRE_PUCHAR p = current_subject + (has_first_char? 1:0);
3521
3522
        /* We don't need to repeat the search if we haven't yet reached the
3523
        place we found it at last time. */
3524
3525
0
        if (p > req_char_ptr)
3526
0
          {
3527
0
          if (req_char != req_char2)
3528
0
            {
3529
0
            while (p < end_subject)
3530
0
              {
3531
0
              int pp = *p++;
3532
0
              if (pp == req_char || pp == req_char2) { p--; break; }
3533
0
              }
3534
0
            }
3535
0
          else
3536
0
            {
3537
0
            while (p < end_subject)
3538
0
              {
3539
0
              if (*p++ == req_char) { p--; break; }
3540
0
              }
3541
0
            }
3542
3543
          /* If we can't find the required character, break the matching loop,
3544
          which will cause a return or PCRE_ERROR_NOMATCH. */
3545
3546
0
          if (p >= end_subject) break;
3547
3548
          /* If we have found the required character, save the point where we
3549
          found it, so that we don't search again next time round the loop if
3550
          the start hasn't passed this character yet. */
3551
3552
0
          req_char_ptr = p;
3553
0
          }
3554
0
        }
3555
0
      }
3556
0
    }   /* End of optimizations that are done when not restarting */
3557
3558
  /* OK, now we can do the business */
3559
3560
0
  md->start_used_ptr = current_subject;
3561
0
  md->recursive = NULL;
3562
3563
0
  rc = internal_dfa_exec(
3564
0
    md,                                /* fixed match data */
3565
0
    md->start_code,                    /* this subexpression's code */
3566
0
    current_subject,                   /* where we currently are */
3567
0
    start_offset,                      /* start offset in subject */
3568
0
    offsets,                           /* offset vector */
3569
0
    offsetcount,                       /* size of same */
3570
0
    workspace,                         /* workspace vector */
3571
0
    wscount,                           /* size of same */
3572
0
    0);                                /* function recurse level */
3573
3574
  /* Anything other than "no match" means we are done, always; otherwise, carry
3575
  on only if not anchored. */
3576
3577
0
  if (rc != PCRE_ERROR_NOMATCH || anchored) return rc;
3578
3579
  /* Advance to the next subject character unless we are at the end of a line
3580
  and firstline is set. */
3581
3582
0
  if (firstline && IS_NEWLINE(current_subject)) break;
3583
0
  current_subject++;
3584
0
#ifdef SUPPORT_UTF
3585
0
  if (utf)
3586
0
    {
3587
0
    ACROSSCHAR(current_subject < end_subject, *current_subject,
3588
0
      current_subject++);
3589
0
    }
3590
0
#endif
3591
0
  if (current_subject > end_subject) break;
3592
3593
  /* If we have just passed a CR and we are now at a LF, and the pattern does
3594
  not contain any explicit matches for \r or \n, and the newline option is CRLF
3595
  or ANY or ANYCRLF, advance the match position by one more character. */
3596
3597
0
  if (current_subject[-1] == CHAR_CR &&
3598
0
      current_subject < end_subject &&
3599
0
      *current_subject == CHAR_NL &&
3600
0
      (re->flags & PCRE_HASCRORLF) == 0 &&
3601
0
        (md->nltype == NLTYPE_ANY ||
3602
0
         md->nltype == NLTYPE_ANYCRLF ||
3603
0
         md->nllen == 2))
3604
0
    current_subject++;
3605
3606
0
  }   /* "Bumpalong" loop */
3607
3608
0
return PCRE_ERROR_NOMATCH;
3609
0
}
3610
3611
/* End of pcre_dfa_exec.c */