@@ -1385,6 +1385,10 @@ ep_rt_utf8_to_utf16le_string (
13851385 if (!str )
13861386 return NULL ;
13871387
1388+ if (len == (size_t ) -1 ) {
1389+ len = strlen (str );
1390+ }
1391+
13881392 if (len == 0 ) {
13891393 // Return an empty string if the length is 0
13901394 CHAR16_T * lpDestEmptyStr = reinterpret_cast < CHAR16_T * > (malloc (1 * sizeof (CHAR16_T )));
@@ -1395,11 +1399,6 @@ ep_rt_utf8_to_utf16le_string (
13951399 return reinterpret_cast < ep_char16_t * > (lpDestEmptyStr );
13961400 }
13971401
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-
14031402 int32_t flags = MINIPAL_MB_NO_REPLACE_INVALID_CHARS | MINIPAL_TREAT_AS_LITTLE_ENDIAN ;
14041403
14051404 size_t ret = minipal_get_length_utf8_to_utf16 (str , len , flags );
@@ -1466,6 +1465,10 @@ ep_rt_utf16_to_utf8_string (
14661465 if (!str )
14671466 return NULL ;
14681467
1468+ if (len == (size_t ) -1 ) {
1469+ len = ep_rt_utf16_string_len (str );
1470+ }
1471+
14691472 if (len == 0 ) {
14701473 // Return an empty string if the length is 0
14711474 char * lpDestEmptyStr = reinterpret_cast < char * > (malloc (1 * sizeof (char )));
@@ -1476,11 +1479,6 @@ ep_rt_utf16_to_utf8_string (
14761479 return reinterpret_cast < ep_char8_t * > (lpDestEmptyStr );
14771480 }
14781481
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-
14841482 size_t ret = minipal_get_length_utf16_to_utf8 (reinterpret_cast < const CHAR16_T * > (str ), len , 0 );
14851483
14861484 if (ret <= 0 )
0 commit comments