From 3300e040d5b70997ae396d2bb19f9a6e9421a46e Mon Sep 17 00:00:00 2001 From: mycoolclub Date: Sat, 27 Sep 2014 08:37:35 +0900 Subject: [PATCH] Bug 943291: Now we use native Windows method to convert strings. r=emk --- widget/windows/nsDataObj.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/widget/windows/nsDataObj.cpp b/widget/windows/nsDataObj.cpp index 53291c36566..adb04267ac6 100644 --- a/widget/windows/nsDataObj.cpp +++ b/widget/windows/nsDataObj.cpp @@ -1292,19 +1292,19 @@ HRESULT nsDataObj::GetText(const nsACString & aDataFlavor, FORMATETC& aFE, STGME if ( aFE.cfFormat == CF_TEXT ) { // Someone is asking for text/plain; convert the unicode (assuming it's present) // to text with the correct platform encoding. - char* plainTextData = nullptr; + size_t bufferSize = sizeof(char)*(len + 2); + char* plainTextData = static_cast(nsMemory::Alloc(bufferSize)); char16_t* castedUnicode = reinterpret_cast(data); - int32_t plainTextLen = 0; - nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, len / 2, &plainTextData, &plainTextLen ); - + int32_t plainTextLen = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)castedUnicode, len / 2 + 1, plainTextData, bufferSize, NULL, NULL); // replace the unicode data with our plaintext data. Recall that |plainTextLen| doesn't include // the null in the length. nsMemory::Free(data); - if ( plainTextData ) { + if ( plainTextLen ) { data = plainTextData; - allocLen = plainTextLen + sizeof(char); + allocLen = plainTextLen; } else { + nsMemory::Free(plainTextData); NS_WARNING ( "Oh no, couldn't convert unicode to plain text" ); return S_OK; }