Project

General

Profile

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

k_takata (Ken Takata), 01/06/2012 09:31 PM

View differences:

regcomp.c
3419 3419
			    UChar *p, int slen, UChar *end,
3420 3420
			    regex_t* reg, Node **rnode)
3421 3421
{
3422
  int r, i, j, len, varlen;
3422
  int r, i, j, len, varlen, varclen;
3423 3423
  Node *anode, *var_anode, *snode, *xnode, *an;
3424 3424
  UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
3425 3425

  
3426 3426
  *rnode = var_anode = NULL_NODE;
3427 3427

  
3428 3428
  varlen = 0;
3429
  varclen = 0;
3429 3430
  for (i = 0; i < item_num; i++) {
3430 3431
    if (items[i].byte_len != slen) {
3431 3432
      varlen = 1;
3432 3433
      break;
3433 3434
    }
3435
    if (items[i].code_len != 1) {
3436
      varclen = 1;
3437
    }
3434 3438
  }
3435 3439

  
3436 3440
  if (varlen != 0) {
......
3515 3519
    }
3516 3520
  }
3517 3521

  
3522
  if (varclen && !varlen)
3523
    return 2;
3518 3524
  return varlen;
3519 3525

  
3520 3526
 mem_err2:
......
3532 3538
#define THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION  8
3533 3539

  
3534 3540
  int r, n, len, alt_num;
3541
  int varlen = 0;
3535 3542
  UChar *start, *end, *p;
3536 3543
  Node *top_root, *root, *snode, *prev_node;
3537 3544
  OnigCaseFoldCodeItem items[ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM];
......
3594 3601

  
3595 3602
      r = expand_case_fold_string_alt(n, items, p, len, end, reg, &prev_node);
3596 3603
      if (r < 0) goto mem_err;
3604
      if (r > 0) varlen = 1;
3597 3605
      if (r == 1) {
3598 3606
	if (IS_NULL(root)) {
3599 3607
	  top_root = prev_node;
......
3607 3615

  
3608 3616
	root = NCAR(prev_node);
3609 3617
      }
3610
      else { /* r == 0 */
3618
      else { /* r == 0 || r == 2 */
3611 3619
	if (IS_NOT_NULL(root)) {
3612 3620
	  if (IS_NULL(onig_node_list_add(root, prev_node))) {
3613 3621
	    onig_node_free(prev_node);
......
3650 3658

  
3651 3659
  /* ending */
3652 3660
  top_root = (IS_NOT_NULL(top_root) ? top_root : prev_node);
3653
  swap_node(node, top_root);
3661
  if (!varlen) {
3662
    /* When all expanded strings are same length, case-insensitive
3663
       BM search will be used. */
3664
    r = update_string_node_case_fold(reg, node);
3665
    if (r == 0) {
3666
      NSTRING_SET_AMBIG(node);
3667
    }
3668
  }
3669
  else {
3670
    swap_node(node, top_root);
3671
    r = 0;
3672
  }
3654 3673
  onig_node_free(top_root);
3655
  return 0;
3674
  return r;
3656 3675

  
3657 3676
 mem_err:
3658 3677
  r = ONIGERR_MEMORY;
......
3856 3875

  
3857 3876
  case NT_STR:
3858 3877
    if (IS_IGNORECASE(reg->options) && !NSTRING_IS_RAW(node)) {
3859
#if 0
3860 3878
      r = expand_case_fold_string(node, reg);
3861
#else
3862
      r = update_string_node_case_fold(reg, node);
3863
      if (r == 0) {
3864
	NSTRING_SET_AMBIG(node);
3865
      }
3866
#endif
3867 3879
    }
3868 3880
    break;
3869 3881

  
......
4145 4157
      clen = enclen(enc, p, end);
4146 4158

  
4147 4159
      for (j = 0; j < n; j++) {
4148
	if (items[j].code_len != 1)
4160
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4149 4161
	  return 1;  /* different length isn't supported. */
4150 4162
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4151 4163
	if (flen != clen)
......
4175 4187
      clen = enclen(enc, p, end);
4176 4188

  
4177 4189
      for (j = 0; j < n; j++) {
4178
	if (items[j].code_len != 1)
4190
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4179 4191
	  return 1;  /* different length isn't supported. */
4180 4192
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4181 4193
	if (flen != clen)
......
4218 4230
      clen = enclen(enc, p, end);
4219 4231

  
4220 4232
      for (j = 0; j < n; j++) {
4221
	if (items[j].code_len != 1)
4233
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4222 4234
	  return 1;  /* different length isn't supported. */
4223 4235
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4224 4236
	if (flen != clen)
......
4248 4260
      clen = enclen(enc, p, end);
4249 4261

  
4250 4262
      for (j = 0; j < n; j++) {
4251
	if (items[j].code_len != 1)
4263
	if ((items[j].code_len != 1) || (items[j].byte_len != clen))
4252 4264
	  return 1;  /* different length isn't supported. */
4253 4265
	flen = ONIGENC_CODE_TO_MBC(enc, items[j].code[0], buf[j]);
4254 4266
	if (flen != clen)
......
5232 5244

  
5233 5245
  if (e->len == 0) return 0;
5234 5246

  
5235
  reg->exact = str_dup(e->s, e->s + e->len);
5247
  reg->exact = (UChar* )xmalloc(e->len);
5236 5248
  CHECK_NULL_RETURN_MEMERR(reg->exact);
5249
  xmemcpy(reg->exact, e->s, e->len);
5237 5250
  reg->exact_end = reg->exact + e->len;
5238 5251

  
5239 5252
  allow_reverse =
5240
-