diff --git a/widget/windows/nsClipboard.cpp b/widget/windows/nsClipboard.cpp index 72648246790f..146ac31a17b5 100644 --- a/widget/windows/nsClipboard.cpp +++ b/widget/windows/nsClipboard.cpp @@ -280,18 +280,16 @@ nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void** aData, uint32_t* aLen) { // Allocate a new memory buffer and copy the data from global memory. // Recall that win98 allocates to nearest DWORD boundary. As a safety - // precaution, allocate an extra 3 bytes (but don't report them in |aLen|!) - // and null them out to ensure that all of our NS_strlen calls will succeed. - // NS_strlen operates on char16_t, so we need 3 NUL bytes to ensure it finds - // a full NUL char16_t when |*aLen| is odd. + // precaution, allocate an extra 2 bytes (but don't report them!) and + // null them out to ensure that all of our strlen calls will succeed. nsresult result = NS_ERROR_FAILURE; if (aHGBL != nullptr) { LPSTR lpStr = (LPSTR)GlobalLock(aHGBL); DWORD allocSize = GlobalSize(aHGBL); - char* data = static_cast(malloc(allocSize + 3)); + char* data = static_cast(malloc(allocSize + sizeof(char16_t))); if (data) { memcpy(data, lpStr, allocSize); - data[allocSize] = data[allocSize + 1] = data[allocSize + 2] + data[allocSize] = data[allocSize + 1] = '\0'; // null terminate for safety GlobalUnlock(aHGBL);