From: Paul Eggert Date: Thu, 1 Sep 2005 21:01:26 +0000 (+0000) Subject: * lib/regex_internal.c (build_wcs_upper_buffer): Fix portability X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7094f1ff70bff426c8b3cc9998c0ae5e44a5f255;hp=1e5cfc92d3a783d911169d1704ae6e37072c327c;p=pspp * 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. --- diff --git a/config/ChangeLog b/config/ChangeLog index d933a19d8d..bcce52d4d1 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,6 +1,6 @@ 2005-09-01 Paul Eggert - * srclist.txt: Add glibc bug 1285. + * srclist.txt: Add glibc bug 1285, 1286. 2005-08-31 Paul Eggert diff --git a/config/srclist.txt b/config/srclist.txt index b6cfcf2ea2..8f2432bf2c 100644 --- 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 @@ $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 diff --git a/lib/ChangeLog b/lib/ChangeLog index 9ec3d79dd6..973388a78a 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,8 @@ 2005-09-01 Paul Eggert + * 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. diff --git a/lib/regex_internal.c b/lib/regex_internal.c index 702563f819..24c61ecf7a 100644 --- a/lib/regex_internal.c +++ b/lib/regex_internal.c @@ -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;