[newlib-cygwin/main] Cygwin: cXXrtomb, mbrtcXX: use function-specific internal state

Corinna Vinschen corinna@sourceware.org
Tue Aug 15 20:35:49 GMT 2023


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=46c4a9072436b01f9239bbac2e9a24bc08755026

commit 46c4a9072436b01f9239bbac2e9a24bc08755026
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Aug 15 22:34:29 2023 +0200
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Tue Aug 15 22:34:29 2023 +0200

    Cygwin: cXXrtomb, mbrtcXX: use function-specific internal state
    
    As described in the previous commit b5111e46424b
    ("struct _reent: add state for unicode functions") every unicode
    conversion function has to use their own state object, if the
    state parameter is NULL.
    
    Fixes: 4f258c55e87f ("Cygwin: Add ISO C11 functions c16rtomb, c32rtomb, mbrtoc16, mbrtoc32.")
    Fixes: c49bc478b4a7 ("Cygwin: Add ISO C2X functions c8rtomb, mbrtoc8")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/strfuncs.cc | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc
index cbcd0ec464ee..66667bdb3a3c 100644
--- a/winsup/cygwin/strfuncs.cc
+++ b/winsup/cygwin/strfuncs.cc
@@ -135,6 +135,12 @@ wcintowcs (wchar_t *dest, wint_t *src, size_t len)
 extern "C" size_t
 c32rtomb (char *s, char32_t wc, mbstate_t *ps)
 {
+  if (ps == NULL)
+    {
+      _REENT_CHECK_MISC(_REENT);
+      ps = &(_REENT_C32RTOMB_STATE(_REENT));
+    }
+
     /* If s is NULL, behave as if s pointed to an internal buffer and wc
        was a null wide character (L'').  wcrtomb will do that for us*/
     if (wc <= 0xffff || !s)
@@ -152,6 +158,12 @@ c32rtomb (char *s, char32_t wc, mbstate_t *ps)
 extern "C" size_t
 c16rtomb (char *s, char16_t wc, mbstate_t *ps)
 {
+  if (ps == NULL)
+    {
+      _REENT_CHECK_MISC(_REENT);
+      ps = &(_REENT_C16RTOMB_STATE(_REENT));
+    }
+
   return wcrtomb (s, (wchar_t) wc, ps);
 }
 
@@ -164,7 +176,7 @@ c8rtomb (char *s, char8_t c8, mbstate_t *ps)
   if (ps == NULL)
     {
       _REENT_CHECK_MISC(reent);
-      ps = &(_REENT_MBRTOWC_STATE(reent));
+      ps = &(_REENT_C8RTOMB_STATE(reent));
     }
 
   if (s == NULL)
@@ -258,6 +270,12 @@ mbrtoc32 (char32_t *pwc, const char *s, size_t n, mbstate_t *ps)
   size_t len, len2;
   wchar_t w1, w2;
 
+  if (ps == NULL)
+    {
+      _REENT_CHECK_MISC(_REENT);
+      ps = &(_REENT_MBRTOC32_STATE(_REENT));
+    }
+
   len = mbrtowc (&w1, s, n, ps);
   if (len == (size_t) -1 || len == (size_t) -2)
     return len;
@@ -299,7 +317,7 @@ mbrtoc16 (char16_t *pwc, const char *s, size_t n, mbstate_t *ps)
   if (ps == NULL)
     {
       _REENT_CHECK_MISC(reent);
-      ps = &(_REENT_MBRTOWC_STATE(reent));
+      ps = &(_REENT_MBRTOC16_STATE(reent));
     }
 
   if (s == NULL)
@@ -352,7 +370,7 @@ mbrtoc8 (char8_t *pc8, const char *s, size_t n, mbstate_t *ps)
   if (ps == NULL)
     {
       _REENT_CHECK_MISC(reent);
-      ps = &(_REENT_MBRTOWC_STATE(reent));
+      ps = &(_REENT_MBRTOC8_STATE(reent));
     }
 
   if (s == NULL)


More information about the Cygwin-cvs mailing list