]> Savannah Git Hosting - gnulib.git/commitdiff
mbrtoc32-regular: Make it work as expected on glibc 2.12.
authorBruno Haible <bruno@clisp.org>
Wed, 16 Aug 2023 21:44:57 +0000 (23:44 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 30 Aug 2023 09:43:32 +0000 (11:43 +0200)
* lib/mbrtoc32.c (mbrtoc32): If necessary, clear the mbstate_t after
mbrtowc() returned.

ChangeLog
lib/mbrtoc32.c

index f8645fcc96aa259eee0236ac362e1d87f4f5e20b..a0ecbd7dee07b582c64f5f7eca237c308e3b5fac 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-08-16  Bruno Haible  <bruno@clisp.org>
+
+       mbrtoc32-regular: Make it work as expected on glibc 2.12.
+       * lib/mbrtoc32.c (mbrtoc32): If necessary, clear the mbstate_t after
+       mbrtowc() returned.
+
 2023-08-16  Bruno Haible  <bruno@clisp.org>
 
        fnmatch: Override fnmatch from glibc versions < 2.22.
index 6a56d93a4b28502936c0ac7784c6dd73d6c459d7..b8d07ccb009dabc30033d331b088b1a67f8f0283 100644 (file)
@@ -246,6 +246,14 @@ mbrtoc32 (char32_t *pwc, const char *s, size_t n, mbstate_t *ps)
   /* char32_t and wchar_t are equivalent.  Use mbrtowc().  */
   wchar_t wc;
   size_t ret = mbrtowc (&wc, s, n, ps);
+
+#  if GNULIB_MBRTOC32_REGULAR
+  /* Ensure that mbrtoc32 is regular.  */
+  if (ret < (size_t) -2 && ! mbsinit (ps))
+    /* This occurs on glibc 2.12.  */
+    mbszero (ps);
+#  endif
+
 #  if GL_CHAR32_T_IS_UNICODE && GL_CHAR32_T_VS_WCHAR_T_NEEDS_CONVERSION
   if (ret < (size_t) -2 && wc != 0)
     {