Skip to content

Commit

Permalink
Fix EventPipe utf8 conversion methods to match between JIT and AOT (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Jul 23, 2023
1 parent 8d2535d commit ecef854
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CHAR16_T *>(malloc(1 * sizeof(CHAR16_T)));
Expand All @@ -1395,11 +1399,6 @@ ep_rt_utf8_to_utf16le_string (
return reinterpret_cast<ep_char16_t*>(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);
Expand Down Expand Up @@ -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<char *>(malloc(1 * sizeof(char)));
Expand All @@ -1476,11 +1479,6 @@ ep_rt_utf16_to_utf8_string (
return reinterpret_cast<ep_char8_t*>(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<const CHAR16_T *>(str), len, 0);

if (ret <= 0)
Expand Down

0 comments on commit ecef854

Please sign in to comment.