]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
mbrtowc: Fix handling of s==NULL on all possible platforms. master
authorBruno Haible <bruno@clisp.org>
Sat, 6 Jun 2026 19:04:18 +0000 (21:04 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 6 Jun 2026 19:12:29 +0000 (21:12 +0200)
* 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.

ChangeLog
lib/mbrtowc.c

index ff29e916b62941bda46a2b4c8a4a54df1db2dec9..e194208c19abcbfda7e20030951bf4399acf5dfe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-06-06  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        mbrtowc: Work around a NetBSD bug in UTF-8 locales, part 2.
index 116bb09fbd2a920385e2541669b7d0ef9e02b512..8026734689fdabfde1819ad60d0434c517e2f21c 100644 (file)
@@ -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__))