diff --git a/docs/notes/bugfix-20898.md b/docs/notes/bugfix-20898.md new file mode 100644 index 00000000000..b2cc48d67c4 --- /dev/null +++ b/docs/notes/bugfix-20898.md @@ -0,0 +1 @@ +# Fix crash when converting from utf16 with revDataFromQuery diff --git a/libexternal/src/osxsupport.cpp b/libexternal/src/osxsupport.cpp index 9210be058eb..ec79555d23b 100644 --- a/libexternal/src/osxsupport.cpp +++ b/libexternal/src/osxsupport.cpp @@ -98,20 +98,14 @@ 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, @@ -119,10 +113,10 @@ char *string_from_utf16(const unsigned short *p_utf16_string, int p_length) | 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; } @@ -130,7 +124,7 @@ char *string_from_utf16(const unsigned short *p_utf16_string, int p_length) len -= processedbytes; destlen += outlength; s += processedbytes; - d += outlength; + dptr += outlength; } return d;