Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
update GetSortKeyNative function
  • Loading branch information
mkhamoyan committed Nov 29, 2023
commit b37beba81f90f07672e37821c0efe034fbf87aa2
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ private unsafe SortKey IcuCreateSortKey(string source, CompareOptions options)
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS
if (GlobalizationMode.Hybrid)
{
if (Interop.Globalization.GetSortKey(_sortHandle, pSource, source.Length, null, 0, options) != sortKeyLength)
if (Interop.Globalization.GetSortKeyNative(m_name, m_name.Length, pSource, source.Length, null, 0, options) != sortKeyLength)
{
throw new ArgumentException(SR.Arg_ExternalException);
}
Expand Down
10 changes: 4 additions & 6 deletions src/native/libs/System.Globalization.Native/pal_collation.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,8 @@ int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, int32_t
@autoreleasepool {
if (cwStrLength == 0)
{
if (sortKey == NULL)
sortKey = malloc(1);
sortKey[0] = '\0';
if (sortKey != NULL)
sortKey[0] = '\0';
return 1;
}
NSString *sourceString = [NSString stringWithCharacters: lpStr length: cwStrLength];
Expand All @@ -330,9 +329,8 @@ int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, int32_t

if (dataToUse != nil) {
const uint8_t *bytesToCopy = (const uint8_t *)[dataToUse bytes];
if (sortKey == NULL)
sortKey = (uint8_t *)malloc(utf8Length);
memcpy(sortKey, bytesToCopy, utf8Length);
if (sortKey != NULL)
memcpy(sortKey, bytesToCopy, utf8Length);
return utf8Length;
}

Expand Down