* lib/regex_internal.c (build_wcs_upper_buffer): Fix portability
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 1 Sep 2005 21:01:26 +0000 (21:01 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 1 Sep 2005 21:01:26 +0000 (21:01 +0000)
bugs in int versus size_t comparisons.
* config/srclist.txt: Add glibc bug 1285, 1286.

config/ChangeLog
config/srclist.txt
lib/ChangeLog
lib/regex_internal.c

index d933a19d8d65085101eac73dbe4eb7eca4d67194..bcce52d4d17f35e8751ac9e2ed8bf466f80779a9 100644 (file)
@@ -1,6 +1,6 @@
 2005-09-01  Paul Eggert  <eggert@cs.ucla.edu>
 
-       * srclist.txt: Add glibc bug 1285.
+       * srclist.txt: Add glibc bug 1285, 1286.
 
 2005-08-31  Paul Eggert  <eggert@cs.ucla.edu>
 
index b6cfcf2ea2a24e8db89c25f5828addebd5a5032d..8f2432bf2c9eb3153cbcc68f160a935b6e96cd9e 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: srclist.txt,v 1.96 2005-09-01 19:41:07 eggert Exp $
+# $Id: srclist.txt,v 1.97 2005-09-01 21:01:27 eggert Exp $
 # Files for which we are not the source.  See ./srclistvars.sh for the
 # variable definitions.
 
@@ -135,6 +135,7 @@ $LIBCSRC/stdlib/getsubopt.c         lib gpl
 # http://sources.redhat.com/bugzilla/show_bug.cgi?id=1282
 # http://sources.redhat.com/bugzilla/show_bug.cgi?id=1284
 # http://sources.redhat.com/bugzilla/show_bug.cgi?id=1285
+# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1286
 #$LIBCSRC/posix/regex_internal.c               lib gpl
 #
 # http://sources.redhat.com/bugzilla/show_bug.cgi?id=1054
index 9ec3d79dd6121c6d7de2be078f084cbcf8566202..973388a78a15fa10b6ed10c6a12069d4a0671847 100644 (file)
@@ -1,5 +1,8 @@
 2005-09-01  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * regex_internal.c (build_wcs_upper_buffer): Fix portability
+       bugs in int versus size_t comparisons.
+
        Use bool where appropriate.
        * regcomp.c (re_set_fastmap): ICASE arg is bool, not int.
        All callers changed.
index 702563f819566d94f559bd942e2931968a311876..24c61ecf7a18fdd4de9a168f72c49f26ac860157 100644 (file)
@@ -301,7 +301,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
          mbclen = mbrtowc (&wc,
                            ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
                             + byte_idx), remain_len, &pstr->cur_state);
-         if (BE (mbclen + 2 > 2, 1))
+         if (BE ((size_t) (mbclen + 2) > 2, 1))
            {
              wchar_t wcu = wc;
              if (iswlower (wc))
@@ -369,7 +369,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
        else
          p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
        mbclen = mbrtowc (&wc, p, remain_len, &pstr->cur_state);
-       if (BE (mbclen + 2 > 2, 1))
+       if (BE ((size_t) (mbclen + 2) > 2, 1))
          {
            wchar_t wcu = wc;
            if (iswlower (wc))
@@ -642,6 +642,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
                        wchar_t wc2;
                        Idx mlen = raw + pstr->len - p;
                        unsigned char buf[6];
+                       size_t mbclen;
 
                        q = p;
                        if (BE (pstr->trans != NULL, 0))
@@ -654,14 +655,13 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
                        /* XXX Don't use mbrtowc, we know which conversion
                           to use (UTF-8 -> UCS4).  */
                        memset (&cur_state, 0, sizeof (cur_state));
-                       mlen = (mbrtowc (&wc2, (const char *) p, mlen,
-                                        &cur_state)
-                               - (raw + offset - p));
-                       if (mlen >= 0)
+                       mbclen = mbrtowc (&wc2, (const char *) p, mlen,
+                                         &cur_state);
+                       if (raw + offset - p <= mbclen && mbclen < (size_t) -2)
                          {
                            memset (&pstr->cur_state, '\0',
                                    sizeof (mbstate_t));
-                           pstr->valid_len = mlen;
+                           pstr->valid_len = mbclen - (raw + offset - p);
                            wc = wc2;
                          }
                        break;