Making sure that are not malloc empty string or image

This commit is contained in:
Maicon Santana 2026-03-03 00:29:21 +00:00
parent 9b78594354
commit 5f8528b324
2 changed files with 48 additions and 37 deletions

View File

@ -840,16 +840,19 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
EM_JS(char*, GetLastPastedText, (void), {
var str = window._lastClipboardString || "";
var length = lengthBytesUTF8(str) + 1;
if (length > 1) {
var ptr = _malloc(length);
stringToUTF8(str, ptr, length);
return ptr;
}
return 0;
});
// Returns the image created by RequestClipboardData from JS memory to Emscripten C memory
EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
if (!window._lastImgData) return 0;
if (window._lastImgData) {
const data = window._lastImgData;
if (data.length > 0) {
const ptr = _malloc(data.length);
HEAPU8.set(data, ptr);
@ -862,6 +865,9 @@ EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
window._lastImgData = null;
return ptr;
}
}
return 0;
});
// Get clipboard text content

View File

@ -818,16 +818,19 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
EM_JS(char*, GetLastPastedText, (void), {
var str = window._lastClipboardString || "";
var length = lengthBytesUTF8(str) + 1;
if (length > 1) {
var ptr = _malloc(length);
stringToUTF8(str, ptr, length);
return ptr;
}
return 0;
});
// Returns the image created by RequestClipboardData from JS memory to Emscripten C memory
EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
if (!window._lastImgData) return 0;
if (window._lastImgData) {
const data = window._lastImgData;
if (data.length > 0) {
const ptr = _malloc(data.length);
HEAPU8.set(data, ptr);
@ -840,6 +843,9 @@ EM_JS(unsigned char*, GetLastPastedImage, (int* width, int* height), {
window._lastImgData = null;
return ptr;
}
}
return 0;
});
// Get clipboard text content
@ -868,7 +874,6 @@ Image GetClipboardImage(void)
return image;
}
// Show mouse cursor
void ShowCursor(void)
{