From: Bruno Haible Date: Sat, 6 Jun 2026 19:04:18 +0000 (+0200) Subject: mbrtowc: Fix handling of s==NULL on all possible platforms. X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=HEAD;p=thirdparty%2Fgnulib.git mbrtowc: Fix handling of s==NULL on all possible platforms. * lib/mbrtowc.c (rpl_mbrtowc): Enable the s==NULL test also on platforms that define only MBRTOWC_NUL_RETVAL_BUG or MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ. --- diff --git a/ChangeLog b/ChangeLog index ff29e916b6..e194208c19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2026-06-06 Bruno Haible + + mbrtowc: Fix handling of s==NULL on all possible platforms. + * lib/mbrtowc.c (rpl_mbrtowc): Enable the s==NULL test also on platforms + that define only MBRTOWC_NUL_RETVAL_BUG or + MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ. + 2026-06-02 Bruno Haible mbrtowc: Work around a NetBSD bug in UTF-8 locales, part 2. diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c index 116bb09fbd..8026734689 100644 --- a/lib/mbrtowc.c +++ b/lib/mbrtowc.c @@ -110,15 +110,14 @@ is_locale_utf8_cached (void) size_t rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { -# if (MBRTOWC_RETVAL_BUG || MBRTOWC_EMPTY_INPUT_BUG || MBRTOWC_INVALID_UTF8_BUG \ - || (GNULIB_WCHAR_SINGLE_LOCALE && __GLIBC__ >= 2)) + /* It's simpler to handle the case s == NULL upfront, than to worry about + this case later, before every test of pwc and n. */ if (s == NULL) { pwc = NULL; s = ""; n = 1; } -# endif # if (MBRTOWC_EMPTY_INPUT_BUG || MBRTOWC_INVALID_UTF8_BUG \ || (GNULIB_WCHAR_SINGLE_LOCALE && __GLIBC__ >= 2 && !__UCLIBC__))