Description
I would expect my callback function to only be called for the mime types it supports -- i.e. ones I've specified in SDL_SetClipboardData.
As it turns out, it can get called with other unrelated mime types.
This is fine by itself, the callback could just check userdata
and determine that the mime type is not one it can handle. But the problem is that the callback can't return a sane value in that case.
From the SDL_ClipboardDataCallback documentation:
Returning NULL or setting length to 0 will cause no data to be sent to the "receiver". It is up to the receiver to handle this. Essentially returning no data is more or less undefined behavior and may cause breakage in receiving applications.
The only logical return value for an invalid mime type is NULL
, but that is explicitly mentioned as undefined behaviour.
What should a SDL_ClipboardDataCallback
do when it is asked to provide a mime type it wasn't registered with?
Repro steps
Set up a callback with SDL_SetClipboardData
and then request a different mime type with SDL_GetClipboardData
-- notice that the callback is unexpectedly called with that different mime type.