@@ -1385,6 +1385,10 @@ ep_rt_utf8_to_utf16le_string (
1385
1385
if (!str )
1386
1386
return NULL ;
1387
1387
1388
+ if (len == (size_t ) -1 ) {
1389
+ len = strlen (str );
1390
+ }
1391
+
1388
1392
if (len == 0 ) {
1389
1393
// Return an empty string if the length is 0
1390
1394
CHAR16_T * lpDestEmptyStr = reinterpret_cast < CHAR16_T * > (malloc (1 * sizeof (CHAR16_T )));
@@ -1395,11 +1399,6 @@ ep_rt_utf8_to_utf16le_string (
1395
1399
return reinterpret_cast < ep_char16_t * > (lpDestEmptyStr );
1396
1400
}
1397
1401
1398
- if (len == (size_t ) -1 ) {
1399
- // Following the pattern used in EventPipe library where it allocates 1 extra character
1400
- len = strlen (str ) + 1 ;
1401
- }
1402
-
1403
1402
int32_t flags = MINIPAL_MB_NO_REPLACE_INVALID_CHARS | MINIPAL_TREAT_AS_LITTLE_ENDIAN ;
1404
1403
1405
1404
size_t ret = minipal_get_length_utf8_to_utf16 (str , len , flags );
@@ -1466,6 +1465,10 @@ ep_rt_utf16_to_utf8_string (
1466
1465
if (!str )
1467
1466
return NULL ;
1468
1467
1468
+ if (len == (size_t ) -1 ) {
1469
+ len = ep_rt_utf16_string_len (str );
1470
+ }
1471
+
1469
1472
if (len == 0 ) {
1470
1473
// Return an empty string if the length is 0
1471
1474
char * lpDestEmptyStr = reinterpret_cast < char * > (malloc (1 * sizeof (char )));
@@ -1476,11 +1479,6 @@ ep_rt_utf16_to_utf8_string (
1476
1479
return reinterpret_cast < ep_char8_t * > (lpDestEmptyStr );
1477
1480
}
1478
1481
1479
- if (len == (size_t ) -1 ) {
1480
- // Following the pattern used in EventPipe library where it allocates 1 extra character
1481
- len = ep_rt_utf16_string_len (str ) + 1 ;
1482
- }
1483
-
1484
1482
size_t ret = minipal_get_length_utf16_to_utf8 (reinterpret_cast < const CHAR16_T * > (str ), len , 0 );
1485
1483
1486
1484
if (ret <= 0 )
0 commit comments