Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/notes/bugfix-20898.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Fix crash when converting from utf16 with revDataFromQuery
26 changes: 10 additions & 16 deletions libexternal/src/osxsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,39 +98,33 @@ char *string_from_utf16(const unsigned short *p_utf16_string, int p_length)
&s_unicode_converter);
}

UniChar *s;
s = (UniChar *)p_utf16_string;

int len;
len = p_length * 2;

char *d;
d = (char *)malloc(p_length);

int destlen;
destlen = 0;

UniChar *s = (UniChar *)p_utf16_string;
int len = p_length * 2;
char *d = (char *)malloc(p_length);
int destlen = 0;
ByteCount processedbytes, outlength;


// Use separate pointer to d string so that we can return the original d
char *dptr = d;
while(len > 1)
{
ConvertFromUnicodeToText(s_unicode_converter, len, (UniChar *)s,
kUnicodeLooseMappingsMask
| kUnicodeStringUnterminatedBit
| kUnicodeUseFallbacksBit, 0, NULL, 0, NULL,
p_length - destlen, &processedbytes,
&outlength, (LogicalAddress)d);
&outlength, (LogicalAddress)dptr);
if (processedbytes == 0)
{
*d = '?';
*dptr = '?';
processedbytes = 2;
outlength = 1;
}

len -= processedbytes;
destlen += outlength;
s += processedbytes;
d += outlength;
dptr += outlength;
}

return d;
Expand Down