changeset 6196:49579c047f1d

* lib/regex_internal.c (build_wcs_upper_buffer): Fix portability bugs in int versus size_t comparisons. * config/srclist.txt: Add glibc bug 1285, 1286.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 01 Sep 2005 21:01:26 +0000
parents 25eaa608fc4e
children 4b3066daba2f
files config/ChangeLog config/srclist.txt lib/ChangeLog lib/regex_internal.c
diffstat 4 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -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>
 
--- a/config/srclist.txt
+++ b/config/srclist.txt
@@ -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 @@
 # 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
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -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.
--- a/lib/regex_internal.c
+++ b/lib/regex_internal.c
@@ -301,7 +301,7 @@
 	  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 @@
 	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 @@
 			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 @@
 			/* 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;