]> pd.if.org Git - pdclib.old/blobdiff - functions/uchar/c16rtomb.c
PDCLIB-2 c16rtomb: did not support NULL destination buffer mode (count output characters)
[pdclib.old] / functions / uchar / c16rtomb.c
index e8f1de780597eb44d4e0b3c6a4356e9bd89f5ba6..ac8c6295cab69bc474549c1c54eb313caedba826 100644 (file)
@@ -24,6 +24,8 @@ size_t c16rtomb_l(
 )\r
 {\r
     const char16_t *restrict psrc = &c16;\r
+    char buf[s ? 0 : MB_CUR_MAX];\r
+    s =      s ? s : buf;\r
 \r
     if(!l->_Codec->__c16stombs) {\r
         // Codec doesn't support direct conversion - translate via UCS-4\r
@@ -58,6 +60,7 @@ size_t c16rtomb_l(
             if((c16 & 0xFC00) == 0xDC00) {\r
                 // Trailing surrogate\r
                 char32_t c32 = (ps->_Surrogate & 0x3FF) << 10 | (c16 & 0x3FF);\r
+                ps->_Surrogate = 0;\r
                 return c32rtomb_l(s, c32, ps, l);\r
             } else {\r
                 // Not a trailing surrogate - encoding error\r