Project

General

Profile

Feature #5820 ยป 0002-bug-ss-i-doesn-t-match-x-DF.patch

k_takata (Ken Takata), 12/31/2011 11:48 PM

View differences:

regcomp.c
3413 3413
			    UChar *p, int slen, UChar *end,
3414 3414
			    regex_t* reg, Node **rnode)
3415 3415
{
3416
  int r, i, j, len, varlen;
3416
  int r, i, j, len, varlen, varclen;
3417 3417
  Node *anode, *var_anode, *snode, *xnode, *an;
3418 3418
  UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
3419 3419

  
3420 3420
  *rnode = var_anode = NULL_NODE;
3421 3421

  
3422 3422
  varlen = 0;
3423
  varclen = 0;
3423 3424
  for (i = 0; i < item_num; i++) {
3424 3425
    if (items[i].byte_len != slen) {
3425 3426
      varlen = 1;
3426 3427
      break;
3427 3428
    }
3429
    if (items[i].code_len != 1) {
3430
      varclen = 1;
3431
    }
3428 3432
  }
3429 3433

  
3430 3434
  if (varlen != 0) {
......
3509 3513
    }
3510 3514
  }
3511 3515

  
3516
  if (varclen && !varlen)
3517
    return 2;
3512 3518
  return varlen;
3513 3519

  
3514 3520
 mem_err2:
......
3526 3532
#define THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION  8
3527 3533

  
3528 3534
  int r, n, len, alt_num;
3535
  int varlen = 0;
3529 3536
  UChar *start, *end, *p;
3530 3537
  Node *top_root, *root, *snode, *prev_node;
3531 3538
  OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
......
3588 3595

  
3589 3596
      r = expand_case_fold_string_alt(n, items, p, len, end, reg, &prev_node);
3590 3597
      if (r < 0) goto mem_err;
3598
      if (r > 0) varlen = 1;
3591 3599
      if (r == 1) {
3592 3600
	if (IS_NULL(root)) {
3593 3601
	  top_root = prev_node;
......
3601 3609

  
3602 3610
	root = NCAR(prev_node);
3603 3611
      }
3604
      else { /* r == 0 */
3612
      else { /* r == 0 || r == 2 */
3605 3613
	if (IS_NOT_NULL(root)) {
3606 3614
	  if (IS_NULL(onig_node_list_add(root, prev_node))) {
3607 3615
	    onig_node_free(prev_node);
......
3644 3652

  
3645 3653
  /* ending */
3646 3654
  top_root = (IS_NOT_NULL(top_root) ? top_root : prev_node);
3647
  swap_node(node, top_root);
3655
  if (!varlen) {
3656
    /* When all expanded strings are same length, case-insensitive
3657
       BM search will be used. */
3658
    r = update_string_node_case_fold(reg, node);
3659
    if (r == 0) {
3660
      NSTRING_SET_AMBIG(node);
3661
    }
3662
  }
3663
  else {
3664
    swap_node(node, top_root);
3665
    r = 0;
3666
  }
3648 3667
  onig_node_free(top_root);
3649
  return 0;
3668
  return r;
3650 3669

  
3651 3670
 mem_err:
3652 3671
  r = ONIGERR_MEMORY;
......
3850 3869

  
3851 3870
  case NT_STR:
3852 3871
    if (IS_IGNORECASE(reg->options) && !NSTRING_IS_RAW(node)) {
3853
#if 0
3854 3872
      r = expand_case_fold_string(node, reg);
3855
#else
3856
      r = update_string_node_case_fold(reg, node);
3857
      if (r == 0) {
3858
	NSTRING_SET_AMBIG(node);
3859
      }
3860
#endif
3861 3873
    }
3862 3874
    break;
3863 3875

  
......
4139 4151
      clen = enclen(enc, p);
4140 4152

  
4141 4153
      for (j = 0; j < n; j++) {
4142
	if (items[j].code_len != 1)
4154
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4143 4155
	  return 1;  /* different length isn't supported. */
4144 4156
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4145 4157
	if (flen != clen)
......
4169 4181
      clen = enclen(enc, p);
4170 4182

  
4171 4183
      for (j = 0; j < n; j++) {
4172
	if (items[j].code_len != 1)
4184
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4173 4185
	  return 1;  /* different length isn't supported. */
4174 4186
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4175 4187
	if (flen != clen)
......
4212 4224
      clen = enclen(enc, p);
4213 4225

  
4214 4226
      for (j = 0; j < n; j++) {
4215
	if (items[j].code_len != 1)
4227
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4216 4228
	  return 1;  /* different length isn't supported. */
4217 4229
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4218 4230
	if (flen != clen)
......
4242 4254
      clen = enclen(enc, p);
4243 4255

  
4244 4256
      for (j = 0; j < n; j++) {
4245
	if (items[j].code_len != 1)
4257
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4246 4258
	  return 1;  /* different length isn't supported. */
4247 4259
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4248 4260
	if (flen != clen)
......
5226 5238

  
5227 5239
  if (e->len == 0) return 0;
5228 5240

  
5229
  reg->exact = str_dup(e->s, e->s + e->len);
5241
  reg->exact = (UChar* )xmalloc(e->len);
5230 5242
  CHECK_NULL_RETURN_MEMERR(reg->exact);
5243
  xmemcpy(reg->exact, e->s, e->len);
5231 5244
  reg->exact_end = reg->exact + e->len;
5232 5245

  
5233 5246
  allow_reverse =
5234
-