]> 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, 16 Aug 2023 21:44:57 +0000 (23:44 +0200)
* lib/mbrtoc32.c (mbrtoc32): If necessary, clear the mbstate_t after
mbrtowc() returned.

ChangeLog
lib/mbrtoc32.c

index 4d6dc1f9dac88eed9dbf1e266933e2281ebdbdd0..4adcb56ad880b3438b5ba2b6435ae1e227a22664 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 558717d517db7f69d4ccac350e68d3aec69c29f6..0933437a4b8d3ca896b6ebfe586a0edb9d70e67c 100644 (file)
@@ -255,6 +255,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)
     {