mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
Handle pasted data of certain types with an odd length.
This commit is contained in:
parent
dbe5dd5e2a
commit
84cc1f3239
1 changed files with 7 additions and 4 deletions
|
|
@ -283,16 +283,19 @@ nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void ** aData, uint32_t * aLe
|
||||||
{
|
{
|
||||||
// Allocate a new memory buffer and copy the data from global memory.
|
// Allocate a new memory buffer and copy the data from global memory.
|
||||||
// Recall that win98 allocates to nearest DWORD boundary. As a safety
|
// Recall that win98 allocates to nearest DWORD boundary. As a safety
|
||||||
// precaution, allocate an extra 2 bytes (but don't report them!) and
|
// precaution, allocate an extra 3 bytes (but don't report them in |aLen|!)
|
||||||
// null them out to ensure that all of our strlen calls will succeed.
|
// 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.
|
||||||
nsresult result = NS_ERROR_FAILURE;
|
nsresult result = NS_ERROR_FAILURE;
|
||||||
if (aHGBL != nullptr) {
|
if (aHGBL != nullptr) {
|
||||||
LPSTR lpStr = (LPSTR) GlobalLock(aHGBL);
|
LPSTR lpStr = (LPSTR) GlobalLock(aHGBL);
|
||||||
DWORD allocSize = GlobalSize(aHGBL);
|
DWORD allocSize = GlobalSize(aHGBL);
|
||||||
char* data = static_cast<char*>(malloc(allocSize + sizeof(char16_t)));
|
char* data = static_cast<char*>(malloc(allocSize + 3));
|
||||||
if ( data ) {
|
if ( data ) {
|
||||||
memcpy ( data, lpStr, allocSize );
|
memcpy ( data, lpStr, allocSize );
|
||||||
data[allocSize] = data[allocSize + 1] = '\0'; // null terminate for safety
|
data[allocSize] = data[allocSize + 1] = data[allocSize + 2] =
|
||||||
|
'\0'; // null terminate for safety
|
||||||
|
|
||||||
GlobalUnlock(aHGBL);
|
GlobalUnlock(aHGBL);
|
||||||
*aData = data;
|
*aData = data;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue