View | Details | Raw Unified | Return to bug 175314
Collapse All | Expand All

(-)b/usr.bin/grep/regex/tre-fastmatch.c (-29 / +43 lines)
Lines 99-104 static int fastcmp(const fastmatch_t *fg, const void *data, Link Here
99
    fg->pattern[siz] = '\0';						\
99
    fg->pattern[siz] = '\0';						\
100
  }									\
100
  }									\
101
101
102
#define CONV_MBS_PAT(src, dest, destsz)					\
103
  {									\
104
    destsz = wcstombs(NULL, src, 0);				\
105
    if (destsz == (size_t)-1)						\
106
      return REG_BADPAT;						\
107
    dest = xmalloc(destsz + 1);					\
108
    if (dest == NULL)						\
109
      return REG_ESPACE;						\
110
    wcstombs(dest, src, destsz);				\
111
    dest[destsz] = '\0';						\
112
  }									\
113
102
#define IS_OUT_OF_BOUNDS						\
114
#define IS_OUT_OF_BOUNDS						\
103
  ((!fg->reversed							\
115
  ((!fg->reversed							\
104
    ? ((type == STR_WIDE) ? ((j + fg->wlen) > len)			\
116
    ? ((type == STR_WIDE) ? ((j + fg->wlen) > len)			\
Lines 631-637 tre_compile_fast(fastmatch_t *fg, const tre_char_t *pat, size_t n, Link Here
631
	    if (escaped)
643
	    if (escaped)
632
	      {
644
	      {
633
		if (!_escmap)
645
		if (!_escmap)
634
		  _escmap = xmalloc(n * sizeof(bool));
646
		  _escmap = xcalloc(n, sizeof(bool));
635
		if (!_escmap)
647
		if (!_escmap)
636
		  {
648
		  {
637
		    xfree(tmp);
649
		    xfree(tmp);
Lines 711-746 badpat: Link Here
711
   * than in to the wide string so traverse the converted string, as well,
723
   * than in to the wide string so traverse the converted string, as well,
712
   * to store these positions.
724
   * to store these positions.
713
   */
725
   */
714
  if (fg->hasdot || (fg->wescmap != NULL))
726
  if (fg->hasdot || (fg->wescmap != NULL)) {
715
    {
727
	if (fg->wescmap != NULL) {
716
      if (fg->wescmap != NULL)
728
		fg->escmap = xcalloc(fg->len, sizeof(bool));
717
	{
729
		if (!fg->escmap) {
718
	  fg->escmap = xmalloc(fg->len * sizeof(bool));
730
			tre_free_fast(fg);
719
	  if (!fg->escmap)
731
			return REG_ESPACE;
720
	    {
732
		}
721
	      tre_free_fast(fg);
722
	      return REG_ESPACE;
723
	    }
724
	}
733
	}
725
734
726
      escaped = false;
735
	escaped = false;
727
      for (unsigned int i = 0; i < fg->len; i++)
736
	char *_checkpat = NULL;
728
	if (fg->pattern[i] == '\\')
737
	size_t _checklen = 0;
729
	  escaped = !escaped;
738
	unsigned int escofs = 0;
730
	else if (fg->pattern[i] == '.' && fg->escmap && escaped)
739
	/* Make a copy of the original pattern, because fg->pattern has already been stripped */
731
	  {
740
	CONV_MBS_PAT(pat, _checkpat, _checklen);
732
	    fg->escmap[i] = true;
741
	for (unsigned int i = 0; i < n; i++) {
733
	    escaped = false;
742
		if (_checkpat[i] == '\\') {
734
	  }
743
			escaped = !escaped;
735
	else if (fg->pattern[i] == '.' && !escaped)
744
			if(escaped)
736
	  {
745
				++ escofs;
737
	    hasdot = i;
746
		} else if (_checkpat[i] == '.' && fg->escmap && escaped) {
738
	    if (firstdot == -1)
747
			fg->escmap[i - escofs] = true;
739
	      firstdot = i;
748
			escaped = false;
740
	  }
749
		} else if (_checkpat[i] == '.' && !escaped) {
741
	else
750
			hasdot = i;
742
	  escaped = false;
751
			if (firstdot == -1)
743
    }
752
				firstdot = i;
753
		} else
754
			escaped = false;
755
	}
756
	xfree(_checkpat);
757
  }
744
#else
758
#else
745
  SAVE_PATTERN(tmp, pos, fg->pattern, fg->len);
759
  SAVE_PATTERN(tmp, pos, fg->pattern, fg->len);
746
  fg->escmap = _escmap;
760
  fg->escmap = _escmap;

Return to bug 175314