* regex_internal.c (re_string_skip_chars): Don't assume WEOF fits
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 11 Aug 2006 18:28:44 +0000 (18:28 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 11 Aug 2006 18:28:44 +0000 (18:28 +0000)
in wchar_t.  Problem reported by Eric Blake.

lib/ChangeLog
lib/regex_internal.c

index e1e4a51..0add2fa 100644 (file)
@@ -1,5 +1,8 @@
 2006-08-11  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * regex_internal.c (re_string_skip_chars): Don't assume WEOF fits
+       in wchar_t.  Problem reported by Eric Blake.
+
        * snprintf.c (snprintf): memcpy LEN bytes, not SIZE - 1, when
        LEN is smaller than SIZE.  Suggested by Bruno Haible.
        Also, help the compiler to keep LEN in a register.
index a377d2b..633db7a 100644 (file)
@@ -488,16 +488,17 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
   mbstate_t prev_st;
   Idx rawbuf_idx;
   size_t mbclen;
-  wchar_t wc = WEOF;
+  wint_t wc = WEOF;
 
   /* Skip the characters which are not necessary to check.  */
   for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len;
        rawbuf_idx < new_raw_idx;)
     {
+      wchar_t wc2;
       Idx remain_len;
       remain_len = pstr->len - rawbuf_idx;
       prev_st = pstr->cur_state;
-      mbclen = mbrtowc (&wc, (const char *) pstr->raw_mbs + rawbuf_idx,
+      mbclen = mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
                        remain_len, &pstr->cur_state);
       if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0))
        {
@@ -509,10 +510,12 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
          mbclen = 1;
          pstr->cur_state = prev_st;
        }
+      else
+       wc = wc2;
       /* Then proceed the next character.  */
       rawbuf_idx += mbclen;
     }
-  *last_wc = (wint_t) wc;
+  *last_wc = wc;
   return rawbuf_idx;
 }
 #endif /* RE_ENABLE_I18N  */