>From 13457cbc5281c271fa198c4302badca33931268a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 5 Sep 2020 15:24:53 +0200 Subject: [PATCH 1/3] unistr/u{8,16,32}-uctomb: Avoid possible trouble with huge strings. * lib/unistr.in.h (u8_uctomb_aux, u8_uctomb, u16_uctomb_aux, u16_uctomb, u32_uctomb): Change type of last argument to ptrdiff_t. * lib/unistr/u8-uctomb.c (u8_uctomb): Likewise. * lib/unistr/u8-uctomb-aux.c (u8_uctomb_aux): Likewise. * lib/unistr/u16-uctomb.c (u16_uctomb): Likewise. * lib/unistr/u16-uctomb-aux.c (u16_uctomb_aux): Likewise. * lib/unistr/u32-uctomb.c (u32_uctomb): Likewise. --- ChangeLog | 11 +++++++++++ lib/unistr.in.h | 18 +++++++++--------- lib/unistr/u16-uctomb-aux.c | 2 +- lib/unistr/u16-uctomb.c | 2 +- lib/unistr/u32-uctomb.c | 2 +- lib/unistr/u8-uctomb-aux.c | 2 +- lib/unistr/u8-uctomb.c | 2 +- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 92320c5..0d50b68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2020-09-05 Bruno Haible + + unistr/u{8,16,32}-uctomb: Avoid possible trouble with huge strings. + * lib/unistr.in.h (u8_uctomb_aux, u8_uctomb, u16_uctomb_aux, u16_uctomb, + u32_uctomb): Change type of last argument to ptrdiff_t. + * lib/unistr/u8-uctomb.c (u8_uctomb): Likewise. + * lib/unistr/u8-uctomb-aux.c (u8_uctomb_aux): Likewise. + * lib/unistr/u16-uctomb.c (u16_uctomb): Likewise. + * lib/unistr/u16-uctomb-aux.c (u16_uctomb_aux): Likewise. + * lib/unistr/u32-uctomb.c (u32_uctomb): Likewise. + 2020-09-01 Paul Eggert manywarnings: remove -Wchkp and -Wabi from C++ too diff --git a/lib/unistr.in.h b/lib/unistr.in.h index 0acfae6..a0fe3db 100644 --- a/lib/unistr.in.h +++ b/lib/unistr.in.h @@ -25,7 +25,7 @@ /* Get bool. */ #include -/* Get size_t. */ +/* Get size_t, ptrdiff_t. */ #include #ifdef __cplusplus @@ -305,13 +305,13 @@ extern int #if GNULIB_UNISTR_U8_UCTOMB || HAVE_LIBUNISTRING /* Auxiliary function, also used by u8_chr, u8_strchr, u8_strrchr. */ extern int - u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n); + u8_uctomb_aux (uint8_t *s, ucs4_t uc, ptrdiff_t n); # if !HAVE_INLINE extern int - u8_uctomb (uint8_t *s, ucs4_t uc, int n); + u8_uctomb (uint8_t *s, ucs4_t uc, ptrdiff_t n); # else static inline int -u8_uctomb (uint8_t *s, ucs4_t uc, int n) +u8_uctomb (uint8_t *s, ucs4_t uc, ptrdiff_t n) { if (uc < 0x80 && n > 0) { @@ -327,13 +327,13 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) #if GNULIB_UNISTR_U16_UCTOMB || HAVE_LIBUNISTRING /* Auxiliary function, also used by u16_chr, u16_strchr, u16_strrchr. */ extern int - u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n); + u16_uctomb_aux (uint16_t *s, ucs4_t uc, ptrdiff_t n); # if !HAVE_INLINE extern int - u16_uctomb (uint16_t *s, ucs4_t uc, int n); + u16_uctomb (uint16_t *s, ucs4_t uc, ptrdiff_t n); # else static inline int -u16_uctomb (uint16_t *s, ucs4_t uc, int n) +u16_uctomb (uint16_t *s, ucs4_t uc, ptrdiff_t n) { if (uc < 0xd800 && n > 0) { @@ -349,10 +349,10 @@ u16_uctomb (uint16_t *s, ucs4_t uc, int n) #if GNULIB_UNISTR_U32_UCTOMB || HAVE_LIBUNISTRING # if !HAVE_INLINE extern int - u32_uctomb (uint32_t *s, ucs4_t uc, int n); + u32_uctomb (uint32_t *s, ucs4_t uc, ptrdiff_t n); # else static inline int -u32_uctomb (uint32_t *s, ucs4_t uc, int n) +u32_uctomb (uint32_t *s, ucs4_t uc, ptrdiff_t n) { if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000)) { diff --git a/lib/unistr/u16-uctomb-aux.c b/lib/unistr/u16-uctomb-aux.c index a136b0a..44fbdd5 100644 --- a/lib/unistr/u16-uctomb-aux.c +++ b/lib/unistr/u16-uctomb-aux.c @@ -21,7 +21,7 @@ #include "unistr.h" int -u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n) +u16_uctomb_aux (uint16_t *s, ucs4_t uc, ptrdiff_t n) { if (uc < 0xd800) { diff --git a/lib/unistr/u16-uctomb.c b/lib/unistr/u16-uctomb.c index b4f2b88..77e52e5 100644 --- a/lib/unistr/u16-uctomb.c +++ b/lib/unistr/u16-uctomb.c @@ -28,7 +28,7 @@ #if !HAVE_INLINE int -u16_uctomb (uint16_t *s, ucs4_t uc, int n) +u16_uctomb (uint16_t *s, ucs4_t uc, ptrdiff_t n) { if (uc < 0xd800) { diff --git a/lib/unistr/u32-uctomb.c b/lib/unistr/u32-uctomb.c index 53e835d..73554f1 100644 --- a/lib/unistr/u32-uctomb.c +++ b/lib/unistr/u32-uctomb.c @@ -28,7 +28,7 @@ #if !HAVE_INLINE int -u32_uctomb (uint32_t *s, ucs4_t uc, int n) +u32_uctomb (uint32_t *s, ucs4_t uc, ptrdiff_t n) { if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000)) { diff --git a/lib/unistr/u8-uctomb-aux.c b/lib/unistr/u8-uctomb-aux.c index 0b5ec90..4e66c95 100644 --- a/lib/unistr/u8-uctomb-aux.c +++ b/lib/unistr/u8-uctomb-aux.c @@ -23,7 +23,7 @@ #include "attribute.h" int -u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n) +u8_uctomb_aux (uint8_t *s, ucs4_t uc, ptrdiff_t n) { int count; diff --git a/lib/unistr/u8-uctomb.c b/lib/unistr/u8-uctomb.c index 7cf3389..395be77 100644 --- a/lib/unistr/u8-uctomb.c +++ b/lib/unistr/u8-uctomb.c @@ -30,7 +30,7 @@ #if !HAVE_INLINE int -u8_uctomb (uint8_t *s, ucs4_t uc, int n) +u8_uctomb (uint8_t *s, ucs4_t uc, ptrdiff_t n) { if (uc < 0x80) { -- 2.7.4