Only call clipboard callbacks with mime types they expect
Also clarified that returning NULL from a callback sends zero length data to the receiver, which should be able to handle that. Fixes https://github.com/libsdl-org/SDL/issues/9586
This commit is contained in:
@@ -173,6 +173,11 @@ void *SDL_GetInternalClipboardData(SDL_VideoDevice *_this, const char *mime_type
|
||||
void *data = NULL;
|
||||
|
||||
if (_this->clipboard_callback) {
|
||||
if (!SDL_HasInternalClipboardData(_this, mime_type)) {
|
||||
// The callback hasn't advertised that it can handle this mime type
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const void *provided_data = _this->clipboard_callback(_this->clipboard_userdata, mime_type, size);
|
||||
if (provided_data) {
|
||||
// Make a copy of it for the caller and guarantee null termination
|
||||
@@ -180,6 +185,8 @@ void *SDL_GetInternalClipboardData(SDL_VideoDevice *_this, const char *mime_type
|
||||
if (data) {
|
||||
SDL_memcpy(data, provided_data, *size);
|
||||
SDL_memset((Uint8 *)data + *size, 0, sizeof(Uint32));
|
||||
} else {
|
||||
*size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user