mirror of
https://github.com/aseprite/aseprite.git
synced 2024-12-29 09:23:32 +00:00
Check GlobalAlloc() return value in set_win32_clipboard_bitmap()
This commit is contained in:
parent
562106c6f0
commit
44258a8442
@ -95,18 +95,22 @@ static void set_win32_clipboard_bitmap(const Image* image, const Mask* mask, Pal
|
|||||||
if (mask) doc::write_mask(os, mask);
|
if (mask) doc::write_mask(os, mask);
|
||||||
if (palette) doc::write_palette(os, palette);
|
if (palette) doc::write_palette(os, palette);
|
||||||
|
|
||||||
size_t size = (size_t)os.tellp();
|
if (os.good()) {
|
||||||
|
size_t size = (size_t)os.tellp();
|
||||||
HGLOBAL hmem = GlobalAlloc(GHND, size+4);
|
HGLOBAL hmem = GlobalAlloc(GHND, size+4);
|
||||||
char* p = (char*)GlobalLock(hmem);
|
if (hmem) {
|
||||||
|
char* p = (char*)GlobalLock(hmem);
|
||||||
*((uint32_t*)p) = size;
|
if (p) {
|
||||||
os.seekp(0);
|
*((uint32_t*)p) = size;
|
||||||
os.read(p+4, size);
|
os.seekp(0);
|
||||||
|
os.read(p+4, size);
|
||||||
GlobalUnlock(hmem);
|
}
|
||||||
SetClipboardData(custom_clipboard_format, hmem);
|
GlobalUnlock(hmem);
|
||||||
GlobalFree(hmem);
|
if (p)
|
||||||
|
SetClipboardData(custom_clipboard_format, hmem);
|
||||||
|
GlobalFree(hmem);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// information to create the memory necessary for the bitmap
|
// information to create the memory necessary for the bitmap
|
||||||
@ -141,6 +145,12 @@ static void set_win32_clipboard_bitmap(const Image* image, const Mask* mask, Pal
|
|||||||
sizeof(BITMAPV5HEADER)
|
sizeof(BITMAPV5HEADER)
|
||||||
+ palette_entries*sizeof(RGBQUAD)
|
+ palette_entries*sizeof(RGBQUAD)
|
||||||
+ scanline*image->height());
|
+ scanline*image->height());
|
||||||
|
if (!hmem) {
|
||||||
|
// TODO cannot copy exception
|
||||||
|
CloseClipboard();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BITMAPV5HEADER* bi = (BITMAPV5HEADER*)GlobalLock(hmem);
|
BITMAPV5HEADER* bi = (BITMAPV5HEADER*)GlobalLock(hmem);
|
||||||
|
|
||||||
bi->bV5Size = sizeof(BITMAPV5HEADER);
|
bi->bV5Size = sizeof(BITMAPV5HEADER);
|
||||||
|
Loading…
Reference in New Issue
Block a user