diff --git a/widget/windows/nsClipboard.cpp b/widget/windows/nsClipboard.cpp index 97e5c675bb68..dc272f1ff856 100644 --- a/widget/windows/nsClipboard.cpp +++ b/widget/windows/nsClipboard.cpp @@ -710,28 +710,17 @@ HRESULT nsClipboard::FillSTGMedium(IDataObject* aDataObject, UINT aFormat, // since Windows also appears to add null termination. See GetGlobalData. template static nsresult GetCharDataFromGlobalData(STGMEDIUM& aStm, CharType** aData, - uint32_t* aByteLen) { + uint32_t* aLen) { uint32_t nBytes = 0; MOZ_TRY(nsClipboard::GetGlobalData(aStm.hGlobal, reinterpret_cast(aData), &nBytes)); auto nChars = nBytes / sizeof(CharType); if (nChars < 1) { - *aByteLen = 0; + *aLen = 0; return NS_OK; } - - const CharType* data = *aData; - if (nChars > 1 && data[nChars - 2] == CharType(0x00) && - data[nChars - 1] == CharType(0x0a)) { - // The char array ends in the nonsense combination null + LF. Remove both. - // Word sometimes does this. - nChars -= 2; - } else if (data[nChars - 1] == CharType(0)) { - // Remove null termination. - nChars -= 1; - } - *aByteLen = nChars * sizeof(CharType); - + bool hasNullTerminator = (*aData)[nChars - 1] == CharType(0); + *aLen = hasNullTerminator ? nBytes - sizeof(CharType) : nBytes; return NS_OK; }