~clint-fewbar/ubuntu/precise/php5/php5-5.4-merge

« back to all changes in this revision

Viewing changes to ext/pcre/pcrelib/pcre_compile.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-02-22 09:46:37 UTC
  • mfrom: (1.1.20) (0.3.18 sid)
  • Revision ID: package-import@ubuntu.com-20110222094637-nlu2tvb7oqgaarl0
Tags: 5.3.5-1ubuntu1
* Merge from debian/unstable. Remaining changes:
 - debian/control:
    * Dropped firebird2.1-dev, libc-client-dev, libmcrypt-dev as it is in universe.
    * Dropped libmysqlclient15-dev, build against mysql 5.1.
    * Dropped libcurl-dev not in the archive.
    * Suggest php5-suhosin rather than recommends.
    * Dropped php5-imap, php5-interbase, php5-mcrypt since we have versions 
      already in universe.
    * Dropped libonig-dev and libqgdbm since its in universe. (will be re-added in lucid+1)
    * Dropped locales-all.
  - modulelist: Drop imap, interbase, sybase, and mcrypt.
  - debian/rules:
    * Dropped building of mcrypt, imap, and interbase.
    * Install apport hook for php5.
    * stop mysql instance on clean just in case we failed in tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
     -ESC_H,                  0,
123
123
     0,                       -ESC_K,
124
124
     0,                       0,
125
 
     0,                       0,
 
125
     -ESC_N,                  0,
126
126
     -ESC_P,                  -ESC_Q,
127
127
     -ESC_R,                  -ESC_S,
128
128
     0,                       0,
169
169
/*  B8 */     0,     0,      0,       0,      0,   ']',    '=',    '-',
170
170
/*  C0 */   '{',-ESC_A, -ESC_B,  -ESC_C, -ESC_D,-ESC_E,      0, -ESC_G,
171
171
/*  C8 */-ESC_H,     0,      0,       0,      0,     0,      0,      0,
172
 
/*  D0 */   '}',     0, -ESC_K,       0,      0,     0,      0, -ESC_P,
 
172
/*  D0 */   '}',     0, -ESC_K,       0,      0,-ESC_N,      0, -ESC_P,
173
173
/*  D8 */-ESC_Q,-ESC_R,      0,       0,      0,     0,      0,      0,
174
174
/*  E0 */  '\\',     0, -ESC_S,       0,      0,-ESC_V, -ESC_W, -ESC_X,
175
175
/*  E8 */     0,-ESC_Z,      0,       0,      0,     0,      0,      0,
186
186
platforms. */
187
187
 
188
188
typedef struct verbitem {
189
 
  int   len;
190
 
  int   op;
 
189
  int   len;                 /* Length of verb name */
 
190
  int   op;                  /* Op when no arg, or -1 if arg mandatory */
 
191
  int   op_arg;              /* Op when arg present, or -1 if not allowed */
191
192
} verbitem;
192
193
 
193
194
static const char verbnames[] =
 
195
  "\0"                       /* Empty name is a shorthand for MARK */
 
196
  STRING_MARK0
194
197
  STRING_ACCEPT0
195
198
  STRING_COMMIT0
196
199
  STRING_F0
200
203
  STRING_THEN;
201
204
 
202
205
static const verbitem verbs[] = {
203
 
  { 6, OP_ACCEPT },
204
 
  { 6, OP_COMMIT },
205
 
  { 1, OP_FAIL },
206
 
  { 4, OP_FAIL },
207
 
  { 5, OP_PRUNE },
208
 
  { 4, OP_SKIP  },
209
 
  { 4, OP_THEN  }
 
206
  { 0, -1,        OP_MARK },
 
207
  { 4, -1,        OP_MARK },
 
208
  { 6, OP_ACCEPT, -1 },
 
209
  { 6, OP_COMMIT, -1 },
 
210
  { 1, OP_FAIL,   -1 },
 
211
  { 4, OP_FAIL,   -1 },
 
212
  { 5, OP_PRUNE,  OP_PRUNE_ARG },
 
213
  { 4, OP_SKIP,   OP_SKIP_ARG  },
 
214
  { 4, OP_THEN,   OP_THEN_ARG  }
210
215
};
211
216
 
212
217
static const int verbcount = sizeof(verbs)/sizeof(verbitem);
254
259
  cbit_xdigit,-1,          0              /* xdigit */
255
260
};
256
261
 
 
262
/* Table of substitutes for \d etc when PCRE_UCP is set. The POSIX class
 
263
substitutes must be in the order of the names, defined above, and there are
 
264
both positive and negative cases. NULL means no substitute. */
 
265
 
 
266
#ifdef SUPPORT_UCP
 
267
static const uschar *substitutes[] = {
 
268
  (uschar *)"\\P{Nd}",    /* \D */
 
269
  (uschar *)"\\p{Nd}",    /* \d */
 
270
  (uschar *)"\\P{Xsp}",   /* \S */       /* NOTE: Xsp is Perl space */
 
271
  (uschar *)"\\p{Xsp}",   /* \s */
 
272
  (uschar *)"\\P{Xwd}",   /* \W */
 
273
  (uschar *)"\\p{Xwd}"    /* \w */
 
274
};
 
275
 
 
276
static const uschar *posix_substitutes[] = {
 
277
  (uschar *)"\\p{L}",     /* alpha */
 
278
  (uschar *)"\\p{Ll}",    /* lower */
 
279
  (uschar *)"\\p{Lu}",    /* upper */
 
280
  (uschar *)"\\p{Xan}",   /* alnum */
 
281
  NULL,                   /* ascii */
 
282
  (uschar *)"\\h",        /* blank */
 
283
  NULL,                   /* cntrl */
 
284
  (uschar *)"\\p{Nd}",    /* digit */
 
285
  NULL,                   /* graph */
 
286
  NULL,                   /* print */
 
287
  NULL,                   /* punct */
 
288
  (uschar *)"\\p{Xps}",   /* space */    /* NOTE: Xps is POSIX space */
 
289
  (uschar *)"\\p{Xwd}",   /* word */
 
290
  NULL,                   /* xdigit */
 
291
  /* Negated cases */
 
292
  (uschar *)"\\P{L}",     /* ^alpha */
 
293
  (uschar *)"\\P{Ll}",    /* ^lower */
 
294
  (uschar *)"\\P{Lu}",    /* ^upper */
 
295
  (uschar *)"\\P{Xan}",   /* ^alnum */
 
296
  NULL,                   /* ^ascii */
 
297
  (uschar *)"\\H",        /* ^blank */
 
298
  NULL,                   /* ^cntrl */
 
299
  (uschar *)"\\P{Nd}",    /* ^digit */
 
300
  NULL,                   /* ^graph */
 
301
  NULL,                   /* ^print */
 
302
  NULL,                   /* ^punct */
 
303
  (uschar *)"\\P{Xps}",   /* ^space */   /* NOTE: Xps is POSIX space */
 
304
  (uschar *)"\\P{Xwd}",   /* ^word */
 
305
  NULL                    /* ^xdigit */
 
306
};
 
307
#define POSIX_SUBSIZE (sizeof(posix_substitutes)/sizeof(uschar *))
 
308
#endif
257
309
 
258
310
#define STRING(a)  # a
259
311
#define XSTRING(s) STRING(s)
317
369
  /* 35 */
318
370
  "invalid condition (?(0)\0"
319
371
  "\\C not allowed in lookbehind assertion\0"
320
 
  "PCRE does not support \\L, \\l, \\N, \\U, or \\u\0"
 
372
  "PCRE does not support \\L, \\l, \\N{name}, \\U, or \\u\0"
321
373
  "number after (?C is > 255\0"
322
374
  "closing ) for (?C expected\0"
323
375
  /* 40 */
343
395
  "inconsistent NEWLINE options\0"
344
396
  "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0"
345
397
  "a numbered reference must not be zero\0"
346
 
  "(*VERB) with an argument is not supported\0"
 
398
  "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"
347
399
  /* 60 */
348
400
  "(*VERB) not recognized\0"
349
401
  "number is too big\0"
351
403
  "digit expected after (?+\0"
352
404
  "] is an invalid data character in JavaScript compatibility mode\0"
353
405
  /* 65 */
354
 
  "different names for subpatterns of the same number are not allowed\0";
 
406
  "different names for subpatterns of the same number are not allowed\0"
 
407
  "(*MARK) must have an argument\0"
 
408
  "this version of PCRE is not compiled with PCRE_UCP support\0"
 
409
  ;
355
410
 
356
411
/* Table to identify digits and hex digits. This is used when compiling
357
412
patterns. Note that the tables in chartables are dependent on the locale, and
584
639
 
585
640
    case CHAR_l:
586
641
    case CHAR_L:
587
 
    case CHAR_N:
588
642
    case CHAR_u:
589
643
    case CHAR_U:
590
644
    *errorcodeptr = ERR37;
822
876
    }
823
877
  }
824
878
 
 
879
/* Perl supports \N{name} for character names, as well as plain \N for "not
 
880
newline". PCRE does not support \N{name}. */
 
881
 
 
882
if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET)
 
883
  *errorcodeptr = ERR37;
 
884
 
 
885
/* If PCRE_UCP is set, we change the values for \d etc. */
 
886
 
 
887
if ((options & PCRE_UCP) != 0 && c <= -ESC_D && c >= -ESC_w)
 
888
  c -= (ESC_DU - ESC_D);
 
889
 
 
890
/* Set the pointer to the final character before returning. */
 
891
 
825
892
*ptrptr = ptr;
826
893
return c;
827
894
}
1060
1127
 
1061
1128
if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1062
1129
  {
1063
 
  if (ptr[1] == CHAR_QUESTION_MARK &&
1064
 
      ptr[2] == CHAR_VERTICAL_LINE)
 
1130
  /* Handle specials such as (*SKIP) or (*UTF8) etc. */
 
1131
 
 
1132
  if (ptr[1] == CHAR_ASTERISK) ptr += 2;
 
1133
 
 
1134
  /* Handle a normal, unnamed capturing parenthesis. */
 
1135
 
 
1136
  else if (ptr[1] != CHAR_QUESTION_MARK)
 
1137
    {
 
1138
    *count += 1;
 
1139
    if (name == NULL && *count == lorn) return *count;
 
1140
    ptr++;
 
1141
    }
 
1142
 
 
1143
  /* All cases now have (? at the start. Remember when we are in a group
 
1144
  where the parenthesis numbers are duplicated. */
 
1145
 
 
1146
  else if (ptr[2] == CHAR_VERTICAL_LINE)
1065
1147
    {
1066
1148
    ptr += 3;
1067
1149
    dup_parens = TRUE;
1068
1150
    }
1069
1151
 
1070
 
  /* Handle a normal, unnamed capturing parenthesis */
 
1152
  /* Handle comments; all characters are allowed until a ket is reached. */
1071
1153
 
1072
 
  else if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK)
 
1154
  else if (ptr[2] == CHAR_NUMBER_SIGN)
1073
1155
    {
1074
 
    *count += 1;
1075
 
    if (name == NULL && *count == lorn) return *count;
1076
 
    ptr++;
 
1156
    for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break;
 
1157
    goto FAIL_EXIT;
1077
1158
    }
1078
1159
 
1079
1160
  /* Handle a condition. If it is an assertion, just carry on so that it
1080
1161
  is processed as normal. If not, skip to the closing parenthesis of the
1081
 
  condition (there can't be any nested parens. */
 
1162
  condition (there can't be any nested parens). */
1082
1163
 
1083
1164
  else if (ptr[2] == CHAR_LEFT_PARENTHESIS)
1084
1165
    {
1090
1171
      }
1091
1172
    }
1092
1173
 
1093
 
  /* We have either (? or (* and not a condition */
 
1174
  /* Start with (? but not a condition. */
1094
1175
 
1095
1176
  else
1096
1177
    {
1212
1293
  else if (*ptr == CHAR_RIGHT_PARENTHESIS)
1213
1294
    {
1214
1295
    if (dup_parens && *count < hwm_count) *count = hwm_count;
1215
 
    *ptrptr = ptr;
1216
 
    return -1;
 
1296
    goto FAIL_EXIT;
1217
1297
    }
1218
1298
 
1219
1299
  else if (*ptr == CHAR_VERTICAL_LINE && dup_parens)
1613
1693
 
1614
1694
  /* Otherwise, we can get the item's length from the table, except that for
1615
1695
  repeated character types, we have to test for \p and \P, which have an extra
1616
 
  two bytes of parameters. */
 
1696
  two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we
 
1697
  must add in its length. */
1617
1698
 
1618
1699
  else
1619
1700
    {
1637
1718
      case OP_TYPEPOSUPTO:
1638
1719
      if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1639
1720
      break;
 
1721
 
 
1722
      case OP_MARK:
 
1723
      case OP_PRUNE_ARG:
 
1724
      case OP_SKIP_ARG:
 
1725
      case OP_THEN_ARG:
 
1726
      code += code[1];
 
1727
      break;
1640
1728
      }
1641
1729
 
1642
1730
    /* Add in the fixed length from the table */
1708
1796
 
1709
1797
  /* Otherwise, we can get the item's length from the table, except that for
1710
1798
  repeated character types, we have to test for \p and \P, which have an extra
1711
 
  two bytes of parameters. */
 
1799
  two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we
 
1800
  must add in its length. */
1712
1801
 
1713
1802
  else
1714
1803
    {
1732
1821
      case OP_TYPEEXACT:
1733
1822
      if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1734
1823
      break;
 
1824
 
 
1825
      case OP_MARK:
 
1826
      case OP_PRUNE_ARG:
 
1827
      case OP_SKIP_ARG:
 
1828
      case OP_THEN_ARG:
 
1829
      code += code[1];
 
1830
      break;
1735
1831
      }
1736
1832
 
1737
1833
    /* Add in the fixed length from the table */
2001
2097
    break;
2002
2098
#endif
2003
2099
 
 
2100
    /* MARK, and PRUNE/SKIP/THEN with an argument must skip over the argument
 
2101
    string. */
 
2102
 
 
2103
    case OP_MARK:
 
2104
    case OP_PRUNE_ARG:
 
2105
    case OP_SKIP_ARG:
 
2106
    case OP_THEN_ARG:
 
2107
    code += code[1];
 
2108
    break;
 
2109
 
2004
2110
    /* None of the remaining opcodes are required to match a character. */
2005
2111
 
2006
2112
    default:
2221
2327
{
2222
2328
*code++ = OP_CALLOUT;
2223
2329
*code++ = 255;
2224
 
PUT(code, 0, ptr - cd->start_pattern);  /* Pattern offset */
2225
 
PUT(code, LINK_SIZE, 0);                /* Default length */
 
2330
PUT(code, 0, (int)(ptr - cd->start_pattern));  /* Pattern offset */
 
2331
PUT(code, LINK_SIZE, 0);                       /* Default length */
2226
2332
return code + 2*LINK_SIZE;
2227
2333
}
2228
2334
 
2247
2353
static void
2248
2354
complete_callout(uschar *previous_callout, const uschar *ptr, compile_data *cd)
2249
2355
{
2250
 
int length = ptr - cd->start_pattern - GET(previous_callout, 2);
 
2356
int length = (int)(ptr - cd->start_pattern - GET(previous_callout, 2));
2251
2357
PUT(previous_callout, 2 + LINK_SIZE, length);
2252
2358
}
2253
2359
 
2297
2403
 
2298
2404
return TRUE;
2299
2405
}
 
2406
 
 
2407
 
 
2408
 
 
2409
/*************************************************
 
2410
*        Check a character and a property        *
 
2411
*************************************************/
 
2412
 
 
2413
/* This function is called by check_auto_possessive() when a property item
 
2414
is adjacent to a fixed character.
 
2415
 
 
2416
Arguments:
 
2417
  c            the character
 
2418
  ptype        the property type
 
2419
  pdata        the data for the type
 
2420
  negated      TRUE if it's a negated property (\P or \p{^)
 
2421
 
 
2422
Returns:       TRUE if auto-possessifying is OK
 
2423
*/
 
2424
 
 
2425
static BOOL
 
2426
check_char_prop(int c, int ptype, int pdata, BOOL negated)
 
2427
{
 
2428
const ucd_record *prop = GET_UCD(c);
 
2429
switch(ptype)
 
2430
  {
 
2431
  case PT_LAMP:
 
2432
  return (prop->chartype == ucp_Lu ||
 
2433
          prop->chartype == ucp_Ll ||
 
2434
          prop->chartype == ucp_Lt) == negated;
 
2435
 
 
2436
  case PT_GC:
 
2437
  return (pdata == _pcre_ucp_gentype[prop->chartype]) == negated;
 
2438
 
 
2439
  case PT_PC:
 
2440
  return (pdata == prop->chartype) == negated;
 
2441
 
 
2442
  case PT_SC:
 
2443
  return (pdata == prop->script) == negated;
 
2444
 
 
2445
  /* These are specials */
 
2446
 
 
2447
  case PT_ALNUM:
 
2448
  return (_pcre_ucp_gentype[prop->chartype] == ucp_L ||
 
2449
          _pcre_ucp_gentype[prop->chartype] == ucp_N) == negated;
 
2450
 
 
2451
  case PT_SPACE:    /* Perl space */
 
2452
  return (_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
 
2453
          c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
 
2454
          == negated;
 
2455
 
 
2456
  case PT_PXSPACE:  /* POSIX space */
 
2457
  return (_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
 
2458
          c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
 
2459
          c == CHAR_FF || c == CHAR_CR)
 
2460
          == negated;
 
2461
 
 
2462
  case PT_WORD:
 
2463
  return (_pcre_ucp_gentype[prop->chartype] == ucp_L ||
 
2464
          _pcre_ucp_gentype[prop->chartype] == ucp_N ||
 
2465
          c == CHAR_UNDERSCORE) == negated;
 
2466
  }
 
2467
return FALSE;
 
2468
}
2300
2469
#endif  /* SUPPORT_UCP */
2301
2470
 
2302
2471
 
2310
2479
sense to automatically possessify the repeated item.
2311
2480
 
2312
2481
Arguments:
2313
 
  op_code       the repeated op code
2314
 
  this          data for this item, depends on the opcode
 
2482
  previous      pointer to the repeated opcode
2315
2483
  utf8          TRUE in UTF-8 mode
2316
 
  utf8_char     used for utf8 character bytes, NULL if not relevant
2317
2484
  ptr           next character in pattern
2318
2485
  options       options bits
2319
2486
  cd            contains pointers to tables etc.
2322
2489
*/
2323
2490
 
2324
2491
static BOOL
2325
 
check_auto_possessive(int op_code, int item, BOOL utf8, uschar *utf8_char,
2326
 
  const uschar *ptr, int options, compile_data *cd)
 
2492
check_auto_possessive(const uschar *previous, BOOL utf8, const uschar *ptr,
 
2493
  int options, compile_data *cd)
2327
2494
{
2328
 
int next;
 
2495
int c, next;
 
2496
int op_code = *previous++;
2329
2497
 
2330
2498
/* Skip whitespace and comments in extended mode */
2331
2499
 
2386
2554
  strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
2387
2555
    return FALSE;
2388
2556
 
2389
 
/* Now compare the next item with the previous opcode. If the previous is a
2390
 
positive single character match, "item" either contains the character or, if
2391
 
"item" is greater than 127 in utf8 mode, the character's bytes are in
2392
 
utf8_char. */
2393
 
 
2394
 
 
2395
 
/* Handle cases when the next item is a character. */
 
2557
/* Now compare the next item with the previous opcode. First, handle cases when
 
2558
the next item is a character. */
2396
2559
 
2397
2560
if (next >= 0) switch(op_code)
2398
2561
  {
2399
2562
  case OP_CHAR:
2400
2563
#ifdef SUPPORT_UTF8
2401
 
  if (utf8 && item > 127) { GETCHAR(item, utf8_char); }
 
2564
  GETCHARTEST(c, previous);
2402
2565
#else
2403
 
  (void)(utf8_char);  /* Keep compiler happy by referencing function argument */
 
2566
  c = *previous;
2404
2567
#endif
2405
 
  return item != next;
 
2568
  return c != next;
2406
2569
 
2407
2570
  /* For CHARNC (caseless character) we must check the other case. If we have
2408
2571
  Unicode property support, we can use it to test the other case of
2410
2573
 
2411
2574
  case OP_CHARNC:
2412
2575
#ifdef SUPPORT_UTF8
2413
 
  if (utf8 && item > 127) { GETCHAR(item, utf8_char); }
 
2576
  GETCHARTEST(c, previous);
 
2577
#else
 
2578
  c = *previous;
2414
2579
#endif
2415
 
  if (item == next) return FALSE;
 
2580
  if (c == next) return FALSE;
2416
2581
#ifdef SUPPORT_UTF8
2417
2582
  if (utf8)
2418
2583
    {
2423
2588
#else
2424
2589
    othercase = NOTACHAR;
2425
2590
#endif
2426
 
    return (unsigned int)item != othercase;
 
2591
    return (unsigned int)c != othercase;
2427
2592
    }
2428
2593
  else
2429
2594
#endif  /* SUPPORT_UTF8 */
2430
 
  return (item != cd->fcc[next]);  /* Non-UTF-8 mode */
 
2595
  return (c != cd->fcc[next]);  /* Non-UTF-8 mode */
2431
2596
 
2432
 
  /* For OP_NOT, "item" must be a single-byte character. */
 
2597
  /* For OP_NOT, its data is always a single-byte character. */
2433
2598
 
2434
2599
  case OP_NOT:
2435
 
  if (item == next) return TRUE;
 
2600
  if ((c = *previous) == next) return TRUE;
2436
2601
  if ((options & PCRE_CASELESS) == 0) return FALSE;
2437
2602
#ifdef SUPPORT_UTF8
2438
2603
  if (utf8)
2444
2609
#else
2445
2610
    othercase = NOTACHAR;
2446
2611
#endif
2447
 
    return (unsigned int)item == othercase;
 
2612
    return (unsigned int)c == othercase;
2448
2613
    }
2449
2614
  else
2450
2615
#endif  /* SUPPORT_UTF8 */
2451
 
  return (item == cd->fcc[next]);  /* Non-UTF-8 mode */
 
2616
  return (c == cd->fcc[next]);  /* Non-UTF-8 mode */
 
2617
 
 
2618
  /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.
 
2619
  When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */
2452
2620
 
2453
2621
  case OP_DIGIT:
2454
2622
  return next > 127 || (cd->ctypes[next] & ctype_digit) == 0;
2491
2659
    case 0x202f:
2492
2660
    case 0x205f:
2493
2661
    case 0x3000:
2494
 
    return op_code != OP_HSPACE;
 
2662
    return op_code == OP_NOT_HSPACE;
2495
2663
    default:
2496
 
    return op_code == OP_HSPACE;
 
2664
    return op_code != OP_NOT_HSPACE;
2497
2665
    }
2498
2666
 
 
2667
  case OP_ANYNL:
2499
2668
  case OP_VSPACE:
2500
2669
  case OP_NOT_VSPACE:
2501
2670
  switch(next)
2507
2676
    case 0x85:
2508
2677
    case 0x2028:
2509
2678
    case 0x2029:
2510
 
    return op_code != OP_VSPACE;
 
2679
    return op_code == OP_NOT_VSPACE;
2511
2680
    default:
2512
 
    return op_code == OP_VSPACE;
 
2681
    return op_code != OP_NOT_VSPACE;
2513
2682
    }
2514
2683
 
 
2684
#ifdef SUPPORT_UCP
 
2685
  case OP_PROP:
 
2686
  return check_char_prop(next, previous[0], previous[1], FALSE);
 
2687
 
 
2688
  case OP_NOTPROP:
 
2689
  return check_char_prop(next, previous[0], previous[1], TRUE);
 
2690
#endif
 
2691
 
2515
2692
  default:
2516
2693
  return FALSE;
2517
2694
  }
2518
2695
 
2519
2696
 
2520
 
/* Handle the case when the next item is \d, \s, etc. */
 
2697
/* Handle the case when the next item is \d, \s, etc. Note that when PCRE_UCP
 
2698
is set, \d turns into ESC_du rather than ESC_d, etc., so ESC_d etc. are
 
2699
generated only when PCRE_UCP is *not* set, that is, when only ASCII
 
2700
characteristics are recognized. Similarly, the opcodes OP_DIGIT etc. are
 
2701
replaced by OP_PROP codes when PCRE_UCP is set. */
2521
2702
 
2522
2703
switch(op_code)
2523
2704
  {
2524
2705
  case OP_CHAR:
2525
2706
  case OP_CHARNC:
2526
2707
#ifdef SUPPORT_UTF8
2527
 
  if (utf8 && item > 127) { GETCHAR(item, utf8_char); }
 
2708
  GETCHARTEST(c, previous);
 
2709
#else
 
2710
  c = *previous;
2528
2711
#endif
2529
2712
  switch(-next)
2530
2713
    {
2531
2714
    case ESC_d:
2532
 
    return item > 127 || (cd->ctypes[item] & ctype_digit) == 0;
 
2715
    return c > 127 || (cd->ctypes[c] & ctype_digit) == 0;
2533
2716
 
2534
2717
    case ESC_D:
2535
 
    return item <= 127 && (cd->ctypes[item] & ctype_digit) != 0;
 
2718
    return c <= 127 && (cd->ctypes[c] & ctype_digit) != 0;
2536
2719
 
2537
2720
    case ESC_s:
2538
 
    return item > 127 || (cd->ctypes[item] & ctype_space) == 0;
 
2721
    return c > 127 || (cd->ctypes[c] & ctype_space) == 0;
2539
2722
 
2540
2723
    case ESC_S:
2541
 
    return item <= 127 && (cd->ctypes[item] & ctype_space) != 0;
 
2724
    return c <= 127 && (cd->ctypes[c] & ctype_space) != 0;
2542
2725
 
2543
2726
    case ESC_w:
2544
 
    return item > 127 || (cd->ctypes[item] & ctype_word) == 0;
 
2727
    return c > 127 || (cd->ctypes[c] & ctype_word) == 0;
2545
2728
 
2546
2729
    case ESC_W:
2547
 
    return item <= 127 && (cd->ctypes[item] & ctype_word) != 0;
 
2730
    return c <= 127 && (cd->ctypes[c] & ctype_word) != 0;
2548
2731
 
2549
2732
    case ESC_h:
2550
2733
    case ESC_H:
2551
 
    switch(item)
 
2734
    switch(c)
2552
2735
      {
2553
2736
      case 0x09:
2554
2737
      case 0x20:
2576
2759
 
2577
2760
    case ESC_v:
2578
2761
    case ESC_V:
2579
 
    switch(item)
 
2762
    switch(c)
2580
2763
      {
2581
2764
      case 0x0a:
2582
2765
      case 0x0b:
2590
2773
      return -next == ESC_v;
2591
2774
      }
2592
2775
 
 
2776
    /* When PCRE_UCP is set, these values get generated for \d etc. Find
 
2777
    their substitutions and process them. The result will always be either
 
2778
    -ESC_p or -ESC_P. Then fall through to process those values. */
 
2779
 
 
2780
#ifdef SUPPORT_UCP
 
2781
    case ESC_du:
 
2782
    case ESC_DU:
 
2783
    case ESC_wu:
 
2784
    case ESC_WU:
 
2785
    case ESC_su:
 
2786
    case ESC_SU:
 
2787
      {
 
2788
      int temperrorcode = 0;
 
2789
      ptr = substitutes[-next - ESC_DU];
 
2790
      next = check_escape(&ptr, &temperrorcode, 0, options, FALSE);
 
2791
      if (temperrorcode != 0) return FALSE;
 
2792
      ptr++;    /* For compatibility */
 
2793
      }
 
2794
    /* Fall through */
 
2795
 
 
2796
    case ESC_p:
 
2797
    case ESC_P:
 
2798
      {
 
2799
      int ptype, pdata, errorcodeptr;
 
2800
      BOOL negated;
 
2801
 
 
2802
      ptr--;      /* Make ptr point at the p or P */
 
2803
      ptype = get_ucp(&ptr, &negated, &pdata, &errorcodeptr);
 
2804
      if (ptype < 0) return FALSE;
 
2805
      ptr++;      /* Point past the final curly ket */
 
2806
 
 
2807
      /* If the property item is optional, we have to give up. (When generated
 
2808
      from \d etc by PCRE_UCP, this test will have been applied much earlier,
 
2809
      to the original \d etc. At this point, ptr will point to a zero byte. */
 
2810
 
 
2811
      if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
 
2812
        strncmp((char *)ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
 
2813
          return FALSE;
 
2814
 
 
2815
      /* Do the property check. */
 
2816
 
 
2817
      return check_char_prop(c, ptype, pdata, (next == -ESC_P) != negated);
 
2818
      }
 
2819
#endif
 
2820
 
2593
2821
    default:
2594
2822
    return FALSE;
2595
2823
    }
2596
2824
 
 
2825
  /* In principle, support for Unicode properties should be integrated here as
 
2826
  well. It means re-organizing the above code so as to get hold of the property
 
2827
  values before switching on the op-code. However, I wonder how many patterns
 
2828
  combine ASCII \d etc with Unicode properties? (Note that if PCRE_UCP is set,
 
2829
  these op-codes are never generated.) */
 
2830
 
2597
2831
  case OP_DIGIT:
2598
2832
  return next == -ESC_D || next == -ESC_s || next == -ESC_W ||
2599
 
         next == -ESC_h || next == -ESC_v;
 
2833
         next == -ESC_h || next == -ESC_v || next == -ESC_R;
2600
2834
 
2601
2835
  case OP_NOT_DIGIT:
2602
2836
  return next == -ESC_d;
2603
2837
 
2604
2838
  case OP_WHITESPACE:
2605
 
  return next == -ESC_S || next == -ESC_d || next == -ESC_w;
 
2839
  return next == -ESC_S || next == -ESC_d || next == -ESC_w || next == -ESC_R;
2606
2840
 
2607
2841
  case OP_NOT_WHITESPACE:
2608
2842
  return next == -ESC_s || next == -ESC_h || next == -ESC_v;
2609
2843
 
2610
2844
  case OP_HSPACE:
2611
 
  return next == -ESC_S || next == -ESC_H || next == -ESC_d || next == -ESC_w;
 
2845
  return next == -ESC_S || next == -ESC_H || next == -ESC_d ||
 
2846
         next == -ESC_w || next == -ESC_v || next == -ESC_R;
2612
2847
 
2613
2848
  case OP_NOT_HSPACE:
2614
2849
  return next == -ESC_h;
2615
2850
 
2616
2851
  /* Can't have \S in here because VT matches \S (Perl anomaly) */
 
2852
  case OP_ANYNL:
2617
2853
  case OP_VSPACE:
2618
2854
  return next == -ESC_V || next == -ESC_d || next == -ESC_w;
2619
2855
 
2620
2856
  case OP_NOT_VSPACE:
2621
 
  return next == -ESC_v;
 
2857
  return next == -ESC_v || next == -ESC_R;
2622
2858
 
2623
2859
  case OP_WORDCHAR:
2624
 
  return next == -ESC_W || next == -ESC_s || next == -ESC_h || next == -ESC_v;
 
2860
  return next == -ESC_W || next == -ESC_s || next == -ESC_h ||
 
2861
         next == -ESC_v || next == -ESC_R;
2625
2862
 
2626
2863
  case OP_NOT_WORDCHAR:
2627
2864
  return next == -ESC_w || next == -ESC_d;
2685
2922
BOOL groupsetfirstbyte = FALSE;
2686
2923
const uschar *ptr = *ptrptr;
2687
2924
const uschar *tempptr;
 
2925
const uschar *nestptr = NULL;
2688
2926
uschar *previous = NULL;
2689
2927
uschar *previous_callout = NULL;
2690
2928
uschar *save_hwm = NULL;
2755
2993
 
2756
2994
  c = *ptr;
2757
2995
 
 
2996
  /* If we are at the end of a nested substitution, revert to the outer level
 
2997
  string. Nesting only happens one level deep. */
 
2998
 
 
2999
  if (c == 0 && nestptr != NULL)
 
3000
    {
 
3001
    ptr = nestptr;
 
3002
    nestptr = NULL;
 
3003
    c = *ptr;
 
3004
    }
 
3005
 
2758
3006
  /* If we are in the pre-compile phase, accumulate the length used for the
2759
3007
  previous cycle of this loop. */
2760
3008
 
2785
3033
      goto FAILED;
2786
3034
      }
2787
3035
 
2788
 
    *lengthptr += code - last_code;
 
3036
    *lengthptr += (int)(code - last_code);
2789
3037
    DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c));
2790
3038
 
2791
3039
    /* If "previous" is set and it is not at the start of the work space, move
2903
3151
        *errorcodeptr = ERR20;
2904
3152
        goto FAILED;
2905
3153
        }
2906
 
      *lengthptr += code - last_code;   /* To include callout length */
 
3154
      *lengthptr += (int)(code - last_code);   /* To include callout length */
2907
3155
      DPRINTF((">> end branch\n"));
2908
3156
      }
2909
3157
    return TRUE;
3108
3356
          ptr++;
3109
3357
          }
3110
3358
 
3111
 
        posix_class = check_posix_name(ptr, tempptr - ptr);
 
3359
        posix_class = check_posix_name(ptr, (int)(tempptr - ptr));
3112
3360
        if (posix_class < 0)
3113
3361
          {
3114
3362
          *errorcodeptr = ERR30;
3122
3370
        if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)
3123
3371
          posix_class = 0;
3124
3372
 
3125
 
        /* We build the bit map for the POSIX class in a chunk of local store
3126
 
        because we may be adding and subtracting from it, and we don't want to
3127
 
        subtract bits that may be in the main map already. At the end we or the
3128
 
        result into the bit map that is being built. */
 
3373
        /* When PCRE_UCP is set, some of the POSIX classes are converted to
 
3374
        different escape sequences that use Unicode properties. */
 
3375
 
 
3376
#ifdef SUPPORT_UCP
 
3377
        if ((options & PCRE_UCP) != 0)
 
3378
          {
 
3379
          int pc = posix_class + ((local_negate)? POSIX_SUBSIZE/2 : 0);
 
3380
          if (posix_substitutes[pc] != NULL)
 
3381
            {
 
3382
            nestptr = tempptr + 1;
 
3383
            ptr = posix_substitutes[pc] - 1;
 
3384
            continue;
 
3385
            }
 
3386
          }
 
3387
#endif
 
3388
        /* In the non-UCP case, we build the bit map for the POSIX class in a
 
3389
        chunk of local store because we may be adding and subtracting from it,
 
3390
        and we don't want to subtract bits that may be in the main map already.
 
3391
        At the end we or the result into the bit map that is being built. */
3129
3392
 
3130
3393
        posix_class *= 3;
3131
3394
 
3169
3432
 
3170
3433
      /* Backslash may introduce a single character, or it may introduce one
3171
3434
      of the specials, which just set a flag. The sequence \b is a special
3172
 
      case. Inside a class (and only there) it is treated as backspace.
3173
 
      Elsewhere it marks a word boundary. Other escapes have preset maps ready
3174
 
      to 'or' into the one we are building. We assume they have more than one
3175
 
      character in them, so set class_charcount bigger than one. */
 
3435
      case. Inside a class (and only there) it is treated as backspace. We
 
3436
      assume that other escapes have more than one character in them, so set
 
3437
      class_charcount bigger than one. Unrecognized escapes fall through and
 
3438
      are either treated as literal characters (by default), or are faulted if
 
3439
      PCRE_EXTRA is set. */
3176
3440
 
3177
3441
      if (c == CHAR_BACKSLASH)
3178
3442
        {
3179
3443
        c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
3180
3444
        if (*errorcodeptr != 0) goto FAILED;
3181
3445
 
3182
 
        if (-c == ESC_b) c = CHAR_BS;       /* \b is backspace in a class */
3183
 
        else if (-c == ESC_X) c = CHAR_X;   /* \X is literal X in a class */
3184
 
        else if (-c == ESC_R) c = CHAR_R;   /* \R is literal R in a class */
 
3446
        if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */
3185
3447
        else if (-c == ESC_Q)            /* Handle start of quoted string */
3186
3448
          {
3187
3449
          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
3198
3460
          register const uschar *cbits = cd->cbits;
3199
3461
          class_charcount += 2;     /* Greater than 1 is what matters */
3200
3462
 
3201
 
          /* Save time by not doing this in the pre-compile phase. */
3202
 
 
3203
 
          if (lengthptr == NULL) switch (-c)
 
3463
          switch (-c)
3204
3464
            {
 
3465
#ifdef SUPPORT_UCP
 
3466
            case ESC_du:     /* These are the values given for \d etc */
 
3467
            case ESC_DU:     /* when PCRE_UCP is set. We replace the */
 
3468
            case ESC_wu:     /* escape sequence with an appropriate \p */
 
3469
            case ESC_WU:     /* or \P to test Unicode properties instead */
 
3470
            case ESC_su:     /* of the default ASCII testing. */
 
3471
            case ESC_SU:
 
3472
            nestptr = ptr;
 
3473
            ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */
 
3474
            class_charcount -= 2;                /* Undo! */
 
3475
            continue;
 
3476
#endif
3205
3477
            case ESC_d:
3206
3478
            for (c = 0; c < 32; c++) classbits[c] |= cbits[c+cbit_digit];
3207
3479
            continue;
3231
3503
            classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
3232
3504
            continue;
3233
3505
 
3234
 
            default:    /* Not recognized; fall through */
3235
 
            break;      /* Need "default" setting to stop compiler warning. */
3236
 
            }
3237
 
 
3238
 
          /* In the pre-compile phase, just do the recognition. */
3239
 
 
3240
 
          else if (c == -ESC_d || c == -ESC_D || c == -ESC_w ||
3241
 
                   c == -ESC_W || c == -ESC_s || c == -ESC_S) continue;
3242
 
 
3243
 
          /* We need to deal with \H, \h, \V, and \v in both phases because
3244
 
          they use extra memory. */
3245
 
 
3246
 
          if (-c == ESC_h)
3247
 
            {
 
3506
            case ESC_h:
3248
3507
            SETBIT(classbits, 0x09); /* VT */
3249
3508
            SETBIT(classbits, 0x20); /* SPACE */
3250
3509
            SETBIT(classbits, 0xa0); /* NSBP */
3268
3527
              }
3269
3528
#endif
3270
3529
            continue;
3271
 
            }
3272
3530
 
3273
 
          if (-c == ESC_H)
3274
 
            {
 
3531
            case ESC_H:
3275
3532
            for (c = 0; c < 32; c++)
3276
3533
              {
3277
3534
              int x = 0xff;
3313
3570
              }
3314
3571
#endif
3315
3572
            continue;
3316
 
            }
3317
3573
 
3318
 
          if (-c == ESC_v)
3319
 
            {
 
3574
            case ESC_v:
3320
3575
            SETBIT(classbits, 0x0a); /* LF */
3321
3576
            SETBIT(classbits, 0x0b); /* VT */
3322
3577
            SETBIT(classbits, 0x0c); /* FF */
3332
3587
              }
3333
3588
#endif
3334
3589
            continue;
3335
 
            }
3336
3590
 
3337
 
          if (-c == ESC_V)
3338
 
            {
 
3591
            case ESC_V:
3339
3592
            for (c = 0; c < 32; c++)
3340
3593
              {
3341
3594
              int x = 0xff;
3365
3618
              }
3366
3619
#endif
3367
3620
            continue;
3368
 
            }
3369
 
 
3370
 
          /* We need to deal with \P and \p in both phases. */
3371
3621
 
3372
3622
#ifdef SUPPORT_UCP
3373
 
          if (-c == ESC_p || -c == ESC_P)
3374
 
            {
3375
 
            BOOL negated;
3376
 
            int pdata;
3377
 
            int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
3378
 
            if (ptype < 0) goto FAILED;
3379
 
            class_utf8 = TRUE;
3380
 
            *class_utf8data++ = ((-c == ESC_p) != negated)?
3381
 
              XCL_PROP : XCL_NOTPROP;
3382
 
            *class_utf8data++ = ptype;
3383
 
            *class_utf8data++ = pdata;
3384
 
            class_charcount -= 2;   /* Not a < 256 character */
3385
 
            continue;
3386
 
            }
 
3623
            case ESC_p:
 
3624
            case ESC_P:
 
3625
              {
 
3626
              BOOL negated;
 
3627
              int pdata;
 
3628
              int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
 
3629
              if (ptype < 0) goto FAILED;
 
3630
              class_utf8 = TRUE;
 
3631
              *class_utf8data++ = ((-c == ESC_p) != negated)?
 
3632
                XCL_PROP : XCL_NOTPROP;
 
3633
              *class_utf8data++ = ptype;
 
3634
              *class_utf8data++ = pdata;
 
3635
              class_charcount -= 2;   /* Not a < 256 character */
 
3636
              continue;
 
3637
              }
3387
3638
#endif
3388
 
          /* Unrecognized escapes are faulted if PCRE is running in its
3389
 
          strict mode. By default, for compatibility with Perl, they are
3390
 
          treated as literals. */
 
3639
            /* Unrecognized escapes are faulted if PCRE is running in its
 
3640
            strict mode. By default, for compatibility with Perl, they are
 
3641
            treated as literals. */
3391
3642
 
3392
 
          if ((options & PCRE_EXTRA) != 0)
3393
 
            {
3394
 
            *errorcodeptr = ERR7;
3395
 
            goto FAILED;
 
3643
            default:
 
3644
            if ((options & PCRE_EXTRA) != 0)
 
3645
              {
 
3646
              *errorcodeptr = ERR7;
 
3647
              goto FAILED;
 
3648
              }
 
3649
            class_charcount -= 2;  /* Undo the default count from above */
 
3650
            c = *ptr;              /* Get the final character and fall through */
 
3651
            break;
3396
3652
            }
3397
 
 
3398
 
          class_charcount -= 2;  /* Undo the default count from above */
3399
 
          c = *ptr;              /* Get the final character and fall through */
3400
3653
          }
3401
3654
 
3402
3655
        /* Fall through if we have a single character (c >= 0). This may be
3466
3719
          d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
3467
3720
          if (*errorcodeptr != 0) goto FAILED;
3468
3721
 
3469
 
          /* \b is backspace; \X is literal X; \R is literal R; any other
3470
 
          special means the '-' was literal */
 
3722
          /* \b is backspace; any other special means the '-' was literal */
3471
3723
 
3472
3724
          if (d < 0)
3473
3725
            {
3474
 
            if (d == -ESC_b) d = CHAR_BS;
3475
 
            else if (d == -ESC_X) d = CHAR_X;
3476
 
            else if (d == -ESC_R) d = CHAR_R; else
 
3726
            if (d == -ESC_b) d = CHAR_BS; else
3477
3727
              {
3478
3728
              ptr = oldptr;
3479
3729
              goto LONE_SINGLE_CHARACTER;  /* A few lines below */
3639
3889
        }
3640
3890
      }
3641
3891
 
3642
 
    /* Loop until ']' reached. This "while" is the end of the "do" above. */
3643
 
 
3644
 
    while ((c = *(++ptr)) != 0 && (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));
3645
 
 
3646
 
    if (c == 0)                          /* Missing terminating ']' */
 
3892
    /* Loop until ']' reached. This "while" is the end of the "do" far above.
 
3893
    If we are at the end of an internal nested string, revert to the outer
 
3894
    string. */
 
3895
 
 
3896
    while (((c = *(++ptr)) != 0 ||
 
3897
           (nestptr != NULL &&
 
3898
             (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != 0)) &&
 
3899
           (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));
 
3900
 
 
3901
    /* Check for missing terminating ']' */
 
3902
 
 
3903
    if (c == 0)
3647
3904
      {
3648
3905
      *errorcodeptr = ERR6;
3649
3906
      goto FAILED;
3650
3907
      }
3651
3908
 
3652
 
 
3653
 
/* This code has been disabled because it would mean that \s counts as
3654
 
an explicit \r or \n reference, and that's not really what is wanted. Now
3655
 
we set the flag only if there is a literal "\r" or "\n" in the class. */
3656
 
 
3657
 
#if 0
3658
 
    /* Remember whether \r or \n are in this class */
3659
 
 
3660
 
    if (negate_class)
3661
 
      {
3662
 
      if ((classbits[1] & 0x24) != 0x24) cd->external_flags |= PCRE_HASCRORLF;
3663
 
      }
3664
 
    else
3665
 
      {
3666
 
      if ((classbits[1] & 0x24) != 0) cd->external_flags |= PCRE_HASCRORLF;
3667
 
      }
3668
 
#endif
3669
 
 
3670
 
 
3671
3909
    /* If class_charcount is 1, we saw precisely one character whose value is
3672
3910
    less than 256. As long as there were no characters >= 128 and there was no
3673
3911
    use of \p or \P, in other words, no use of any XCLASS features, we can
3731
3969
 
3732
3970
    /* If there are characters with values > 255, we have to compile an
3733
3971
    extended class, with its own opcode, unless there was a negated special
3734
 
    such as \S in the class, because in that case all characters > 255 are in
3735
 
    the class, so any that were explicitly given as well can be ignored. If
3736
 
    (when there are explicit characters > 255 that must be listed) there are no
3737
 
    characters < 256, we can omit the bitmap in the actual compiled code. */
 
3972
    such as \S in the class, and PCRE_UCP is not set, because in that case all
 
3973
    characters > 255 are in the class, so any that were explicitly given as
 
3974
    well can be ignored. If (when there are explicit characters > 255 that must
 
3975
    be listed) there are no characters < 256, we can omit the bitmap in the
 
3976
    actual compiled code. */
3738
3977
 
3739
3978
#ifdef SUPPORT_UTF8
3740
 
    if (class_utf8 && !should_flip_negation)
 
3979
    if (class_utf8 && (!should_flip_negation || (options & PCRE_UCP) != 0))
3741
3980
      {
3742
3981
      *class_utf8data++ = XCL_END;    /* Marks the end of extra data */
3743
3982
      *code++ = OP_XCLASS;
3763
4002
      }
3764
4003
#endif
3765
4004
 
3766
 
    /* If there are no characters > 255, set the opcode to OP_CLASS or
3767
 
    OP_NCLASS, depending on whether the whole class was negated and whether
3768
 
    there were negative specials such as \S in the class. Then copy the 32-byte
3769
 
    map into the code vector, negating it if necessary. */
 
4005
    /* If there are no characters > 255, or they are all to be included or
 
4006
    excluded, set the opcode to OP_CLASS or OP_NCLASS, depending on whether the
 
4007
    whole class was negated and whether there were negative specials such as \S
 
4008
    (non-UCP) in the class. Then copy the 32-byte map into the code vector,
 
4009
    negating it if necessary. */
3770
4010
 
3771
4011
    *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;
3772
4012
    if (negate_class)
3890
4130
 
3891
4131
      if (!possessive_quantifier &&
3892
4132
          repeat_max < 0 &&
3893
 
          check_auto_possessive(*previous, c, utf8, utf8_char, ptr + 1,
3894
 
            options, cd))
 
4133
          check_auto_possessive(previous, utf8, ptr + 1, options, cd))
3895
4134
        {
3896
4135
        repeat_type = 0;    /* Force greedy */
3897
4136
        possessive_quantifier = TRUE;
3912
4151
      c = previous[1];
3913
4152
      if (!possessive_quantifier &&
3914
4153
          repeat_max < 0 &&
3915
 
          check_auto_possessive(OP_NOT, c, utf8, NULL, ptr + 1, options, cd))
 
4154
          check_auto_possessive(previous, utf8, ptr + 1, options, cd))
3916
4155
        {
3917
4156
        repeat_type = 0;    /* Force greedy */
3918
4157
        possessive_quantifier = TRUE;
3936
4175
 
3937
4176
      if (!possessive_quantifier &&
3938
4177
          repeat_max < 0 &&
3939
 
          check_auto_possessive(c, 0, utf8, NULL, ptr + 1, options, cd))
 
4178
          check_auto_possessive(previous, utf8, ptr + 1, options, cd))
3940
4179
        {
3941
4180
        repeat_type = 0;    /* Force greedy */
3942
4181
        possessive_quantifier = TRUE;
4146
4385
      {
4147
4386
      register int i;
4148
4387
      int ketoffset = 0;
4149
 
      int len = code - previous;
 
4388
      int len = (int)(code - previous);
4150
4389
      uschar *bralink = NULL;
4151
4390
 
4152
4391
      /* Repeating a DEFINE group is pointless */
4167
4406
        {
4168
4407
        register uschar *ket = previous;
4169
4408
        do ket += GET(ket, 1); while (*ket != OP_KET);
4170
 
        ketoffset = code - ket;
 
4409
        ketoffset = (int)(code - ket);
4171
4410
        }
4172
4411
 
4173
4412
      /* The case of a zero minimum is special because of the need to stick
4235
4474
          /* We chain together the bracket offset fields that have to be
4236
4475
          filled in later when the ends of the brackets are reached. */
4237
4476
 
4238
 
          offset = (bralink == NULL)? 0 : previous - bralink;
 
4477
          offset = (bralink == NULL)? 0 : (int)(previous - bralink);
4239
4478
          bralink = previous;
4240
4479
          PUTINC(previous, 0, offset);
4241
4480
          }
4344
4583
            {
4345
4584
            int offset;
4346
4585
            *code++ = OP_BRA;
4347
 
            offset = (bralink == NULL)? 0 : code - bralink;
 
4586
            offset = (bralink == NULL)? 0 : (int)(code - bralink);
4348
4587
            bralink = code;
4349
4588
            PUTINC(code, 0, offset);
4350
4589
            }
4365
4604
        while (bralink != NULL)
4366
4605
          {
4367
4606
          int oldlinkoffset;
4368
 
          int offset = code - bralink + 1;
 
4607
          int offset = (int)(code - bralink + 1);
4369
4608
          uschar *bra = code - offset;
4370
4609
          oldlinkoffset = GET(bra, 1);
4371
4610
          bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset;
4453
4692
#endif
4454
4693
        }
4455
4694
 
4456
 
      len = code - tempcode;
 
4695
      len = (int)(code - tempcode);
4457
4696
      if (len > 0) switch (*tempcode)
4458
4697
        {
4459
4698
        case OP_STAR:  *tempcode = OP_POSSTAR; break;
4512
4751
 
4513
4752
    /* First deal with various "verbs" that can be introduced by '*'. */
4514
4753
 
4515
 
    if (*(++ptr) == CHAR_ASTERISK && (cd->ctypes[ptr[1]] & ctype_letter) != 0)
 
4754
    if (*(++ptr) == CHAR_ASTERISK &&
 
4755
         ((cd->ctypes[ptr[1]] & ctype_letter) != 0 || ptr[1] == ':'))
4516
4756
      {
4517
4757
      int i, namelen;
 
4758
      int arglen = 0;
4518
4759
      const char *vn = verbnames;
4519
 
      const uschar *name = ++ptr;
 
4760
      const uschar *name = ptr + 1;
 
4761
      const uschar *arg = NULL;
4520
4762
      previous = NULL;
4521
4763
      while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};
 
4764
      namelen = (int)(ptr - name);
 
4765
 
4522
4766
      if (*ptr == CHAR_COLON)
4523
4767
        {
4524
 
        *errorcodeptr = ERR59;   /* Not supported */
4525
 
        goto FAILED;
 
4768
        arg = ++ptr;
 
4769
        while ((cd->ctypes[*ptr] & (ctype_letter|ctype_digit)) != 0
 
4770
          || *ptr == '_') ptr++;
 
4771
        arglen = (int)(ptr - arg);
4526
4772
        }
 
4773
 
4527
4774
      if (*ptr != CHAR_RIGHT_PARENTHESIS)
4528
4775
        {
4529
4776
        *errorcodeptr = ERR60;
4530
4777
        goto FAILED;
4531
4778
        }
4532
 
      namelen = ptr - name;
 
4779
 
 
4780
      /* Scan the table of verb names */
 
4781
 
4533
4782
      for (i = 0; i < verbcount; i++)
4534
4783
        {
4535
4784
        if (namelen == verbs[i].len &&
4547
4796
              PUT2INC(code, 0, oc->number);
4548
4797
              }
4549
4798
            }
4550
 
          *code++ = verbs[i].op;
4551
 
          break;
 
4799
 
 
4800
          /* Handle the cases with/without an argument */
 
4801
 
 
4802
          if (arglen == 0)
 
4803
            {
 
4804
            if (verbs[i].op < 0)   /* Argument is mandatory */
 
4805
              {
 
4806
              *errorcodeptr = ERR66;
 
4807
              goto FAILED;
 
4808
              }
 
4809
            *code++ = verbs[i].op;
 
4810
            }
 
4811
 
 
4812
          else
 
4813
            {
 
4814
            if (verbs[i].op_arg < 0)   /* Argument is forbidden */
 
4815
              {
 
4816
              *errorcodeptr = ERR59;
 
4817
              goto FAILED;
 
4818
              }
 
4819
            *code++ = verbs[i].op_arg;
 
4820
            *code++ = arglen;
 
4821
            memcpy(code, arg, arglen);
 
4822
            code += arglen;
 
4823
            *code++ = 0;
 
4824
            }
 
4825
 
 
4826
          break;  /* Found verb, exit loop */
4552
4827
          }
 
4828
 
4553
4829
        vn += verbs[i].len + 1;
4554
4830
        }
4555
 
      if (i < verbcount) continue;
4556
 
      *errorcodeptr = ERR60;
 
4831
 
 
4832
      if (i < verbcount) continue;    /* Successfully handled a verb */
 
4833
      *errorcodeptr = ERR60;          /* Verb not recognized */
4557
4834
      goto FAILED;
4558
4835
      }
4559
4836
 
4672
4949
              recno * 10 + *ptr - CHAR_0 : -1;
4673
4950
          ptr++;
4674
4951
          }
4675
 
        namelen = ptr - name;
 
4952
        namelen = (int)(ptr - name);
4676
4953
 
4677
4954
        if ((terminator > 0 && *ptr++ != terminator) ||
4678
4955
            *ptr++ != CHAR_RIGHT_PARENTHESIS)
4868
5145
            goto FAILED;
4869
5146
            }
4870
5147
          *code++ = n;
4871
 
          PUT(code, 0, ptr - cd->start_pattern + 1);  /* Pattern offset */
4872
 
          PUT(code, LINK_SIZE, 0);                    /* Default length */
 
5148
          PUT(code, 0, (int)(ptr - cd->start_pattern + 1)); /* Pattern offset */
 
5149
          PUT(code, LINK_SIZE, 0);                          /* Default length */
4873
5150
          code += 2 * LINK_SIZE;
4874
5151
          }
4875
5152
        previous = NULL;
4902
5179
          name = ++ptr;
4903
5180
 
4904
5181
          while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++;
4905
 
          namelen = ptr - name;
 
5182
          namelen = (int)(ptr - name);
4906
5183
 
4907
5184
          /* In the pre-compile phase, just do a syntax check. */
4908
5185
 
5032
5309
        NAMED_REF_OR_RECURSE:
5033
5310
        name = ++ptr;
5034
5311
        while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++;
5035
 
        namelen = ptr - name;
 
5312
        namelen = (int)(ptr - name);
5036
5313
 
5037
5314
        /* In the pre-compile phase, do a syntax check and set a dummy
5038
5315
        reference number. */
5201
5478
              of the group. */
5202
5479
 
5203
5480
              called = cd->start_code + recno;
5204
 
              PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);
 
5481
              PUTINC(cd->hwm, 0, (int)(code + 2 + LINK_SIZE - cd->start_code));
5205
5482
              }
5206
5483
 
5207
5484
            /* If not a forward reference, and the subpattern is still open,
5225
5502
          code += 1 + LINK_SIZE;
5226
5503
 
5227
5504
          *code = OP_RECURSE;
5228
 
          PUT(code, 1, called - cd->start_code);
 
5505
          PUT(code, 1, (int)(called - cd->start_code));
5229
5506
          code += 1 + LINK_SIZE;
5230
5507
 
5231
5508
          *code = OP_KET;
5336
5613
        }     /* End of switch for character following (? */
5337
5614
      }       /* End of (? handling */
5338
5615
 
5339
 
    /* Opening parenthesis not followed by '?'. If PCRE_NO_AUTO_CAPTURE is set,
5340
 
    all unadorned brackets become non-capturing and behave like (?:...)
 
5616
    /* Opening parenthesis not followed by '*' or '?'. If PCRE_NO_AUTO_CAPTURE
 
5617
    is set, all unadorned brackets become non-capturing and behave like (?:...)
5341
5618
    brackets. */
5342
5619
 
5343
5620
    else if ((options & PCRE_NO_AUTO_CAPTURE) != 0)
5529
5806
 
5530
5807
    /* ===================================================================*/
5531
5808
    /* Handle metasequences introduced by \. For ones like \d, the ESC_ values
5532
 
    are arranged to be the negation of the corresponding OP_values. For the
5533
 
    back references, the values are ESC_REF plus the reference number. Only
5534
 
    back references and those types that consume a character may be repeated.
5535
 
    We can test for values between ESC_b and ESC_Z for the latter; this may
5536
 
    have to change if any new ones are ever created. */
 
5809
    are arranged to be the negation of the corresponding OP_values in the
 
5810
    default case when PCRE_UCP is not set. For the back references, the values
 
5811
    are ESC_REF plus the reference number. Only back references and those types
 
5812
    that consume a character may be repeated. We can test for values between
 
5813
    ESC_b and ESC_Z for the latter; this may have to change if any new ones are
 
5814
    ever created. */
5537
5815
 
5538
5816
    case CHAR_BACKSLASH:
5539
5817
    tempptr = ptr;
5693
5971
#endif
5694
5972
 
5695
5973
      /* For the rest (including \X when Unicode properties are supported), we
5696
 
      can obtain the OP value by negating the escape value. */
 
5974
      can obtain the OP value by negating the escape value in the default
 
5975
      situation when PCRE_UCP is not set. When it *is* set, we substitute
 
5976
      Unicode property tests. */
5697
5977
 
5698
5978
      else
5699
5979
        {
5700
 
        previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
5701
 
        *code++ = -c;
 
5980
#ifdef SUPPORT_UCP
 
5981
        if (-c >= ESC_DU && -c <= ESC_wu)
 
5982
          {
 
5983
          nestptr = ptr + 1;                   /* Where to resume */
 
5984
          ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */
 
5985
          }
 
5986
        else
 
5987
#endif
 
5988
          {
 
5989
          previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
 
5990
          *code++ = -c;
 
5991
          }
5702
5992
        }
5703
5993
      continue;
5704
5994
      }
6030
6320
    {
6031
6321
    if (lengthptr == NULL)
6032
6322
      {
6033
 
      int branch_length = code - last_branch;
 
6323
      int branch_length = (int)(code - last_branch);
6034
6324
      do
6035
6325
        {
6036
6326
        int prev_length = GET(last_branch, 1);
6044
6334
    /* Fill in the ket */
6045
6335
 
6046
6336
    *code = OP_KET;
6047
 
    PUT(code, 1, code - start_bracket);
 
6337
    PUT(code, 1, (int)(code - start_bracket));
6048
6338
    code += 1 + LINK_SIZE;
6049
6339
 
6050
6340
    /* If it was a capturing subpattern, check to see if it contained any
6059
6349
          code - start_bracket);
6060
6350
        *start_bracket = OP_ONCE;
6061
6351
        code += 1 + LINK_SIZE;
6062
 
        PUT(start_bracket, 1, code - start_bracket);
 
6352
        PUT(start_bracket, 1, (int)(code - start_bracket));
6063
6353
        *code = OP_KET;
6064
 
        PUT(code, 1, code - start_bracket);
 
6354
        PUT(code, 1, (int)(code - start_bracket));
6065
6355
        code += 1 + LINK_SIZE;
6066
6356
        length += 2 + 2*LINK_SIZE;
6067
6357
        }
6116
6406
  else
6117
6407
    {
6118
6408
    *code = OP_ALT;
6119
 
    PUT(code, 1, code - last_branch);
 
6409
    PUT(code, 1, (int)(code - last_branch));
6120
6410
    bc.current_branch = last_branch = code;
6121
6411
    code += 1 + LINK_SIZE;
6122
6412
    }
6435
6725
int firstbyte, reqbyte, newline;
6436
6726
int errorcode = 0;
6437
6727
int skipatstart = 0;
6438
 
BOOL utf8 = (options & PCRE_UTF8) != 0;
 
6728
BOOL utf8;
6439
6729
size_t size;
6440
6730
uschar *code;
6441
6731
const uschar *codestart;
6505
6795
 
6506
6796
  if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0)
6507
6797
    { skipatstart += 7; options |= PCRE_UTF8; continue; }
 
6798
  else if (strncmp((char *)(ptr+skipatstart+2), STRING_UCP_RIGHTPAR, 4) == 0)
 
6799
    { skipatstart += 6; options |= PCRE_UCP; continue; }
6508
6800
 
6509
6801
  if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)
6510
6802
    { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
6529
6821
  else break;
6530
6822
  }
6531
6823
 
 
6824
utf8 = (options & PCRE_UTF8) != 0;
 
6825
 
6532
6826
/* Can't support UTF8 unless PCRE has been compiled to include the code. */
6533
6827
 
6534
6828
#ifdef SUPPORT_UTF8
6546
6840
  }
6547
6841
#endif
6548
6842
 
 
6843
/* Can't support UCP unless PCRE has been compiled to include the code. */
 
6844
 
 
6845
#ifndef SUPPORT_UCP
 
6846
if ((options & PCRE_UCP) != 0)
 
6847
  {
 
6848
  errorcode = ERR67;
 
6849
  goto PCRE_EARLY_ERROR_RETURN;
 
6850
  }
 
6851
#endif
 
6852
 
6549
6853
/* Check validity of \R options. */
6550
6854
 
6551
6855
switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
6674
6978
pointers. */
6675
6979
 
6676
6980
re->magic_number = MAGIC_NUMBER;
6677
 
re->size = size;
 
6981
re->size = (int)size;
6678
6982
re->options = cd->external_options;
6679
6983
re->flags = cd->external_flags;
6680
6984
re->dummy1 = 0;
6745
7049
  recno = GET(codestart, offset);
6746
7050
  groupptr = _pcre_find_bracket(codestart, utf8, recno);
6747
7051
  if (groupptr == NULL) errorcode = ERR53;
6748
 
    else PUT(((uschar *)codestart), offset, groupptr - codestart);
 
7052
    else PUT(((uschar *)codestart), offset, (int)(groupptr - codestart));
6749
7053
  }
6750
7054
 
6751
7055
/* Give an error if there's back reference to a non-existent capturing
6800
7104
  {
6801
7105
  (pcre_free)(re);
6802
7106
  PCRE_EARLY_ERROR_RETURN:
6803
 
  *erroroffset = ptr - (const uschar *)pattern;
 
7107
  *erroroffset = (int)(ptr - (const uschar *)pattern);
6804
7108
  PCRE_EARLY_ERROR_RETURN2:
6805
7109
  *errorptr = find_error_text(errorcode);
6806
7110
  if (errorcodeptr != NULL) *errorcodeptr = errorcode;