From ecef854c27861d9d1e25a3d7de76295cd8a92d3b Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 23 Jul 2023 09:27:36 -0700 Subject: [PATCH] Fix EventPipe utf8 conversion methods to match between JIT and AOT (#89353) --- src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index ce3178d..1379d85 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -1385,6 +1385,10 @@ ep_rt_utf8_to_utf16le_string ( if (!str) return NULL; + if (len == (size_t) -1) { + len = strlen(str); + } + if (len == 0) { // Return an empty string if the length is 0 CHAR16_T * lpDestEmptyStr = reinterpret_cast(malloc(1 * sizeof(CHAR16_T))); @@ -1395,11 +1399,6 @@ ep_rt_utf8_to_utf16le_string ( return reinterpret_cast(lpDestEmptyStr); } - if (len == (size_t) -1) { - // Following the pattern used in EventPipe library where it allocates 1 extra character - len = strlen(str) + 1; - } - int32_t flags = MINIPAL_MB_NO_REPLACE_INVALID_CHARS | MINIPAL_TREAT_AS_LITTLE_ENDIAN; size_t ret = minipal_get_length_utf8_to_utf16 (str, len, flags); @@ -1466,6 +1465,10 @@ ep_rt_utf16_to_utf8_string ( if (!str) return NULL; + if (len == (size_t) -1) { + len = ep_rt_utf16_string_len (str); + } + if (len == 0) { // Return an empty string if the length is 0 char * lpDestEmptyStr = reinterpret_cast(malloc(1 * sizeof(char))); @@ -1476,11 +1479,6 @@ ep_rt_utf16_to_utf8_string ( return reinterpret_cast(lpDestEmptyStr); } - if (len == (size_t) -1) { - // Following the pattern used in EventPipe library where it allocates 1 extra character - len = ep_rt_utf16_string_len (str) + 1; - } - size_t ret = minipal_get_length_utf16_to_utf8 (reinterpret_cast(str), len, 0); if (ret <= 0) -- 2.7.4