From fcdd03a0208da54b1be93fc628c88c41d8f30c98 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 10 Sep 2024 13:24:50 +0200 Subject: [PATCH] [client,x11] fix clipboard cache Use new function format_to_cache_slot to convert a clipboard format to a valid key value for wHashTable. This avoids issues with our synthesized CF_RAW format (value 0) which is an invalid key for wHashTable --- client/X11/xf_cliprdr.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index 637f9cb2c..9ceb1bc1c 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -1338,6 +1338,17 @@ void xf_cliprdr_clear_cached_data(xfClipboard* clipboard) ClipboardUnlock(clipboard->system); } +static void* format_to_cache_slot(UINT32 format) +{ + union + { + uintptr_t uptr; + void* vptr; + } cnv; + cnv.uptr = 0x100000000ULL + format; + return cnv.vptr; +} + static UINT32 get_dst_format_id_for_local_request(xfClipboard* clipboard, const xfCliprdrFormat* format) { @@ -1452,7 +1463,7 @@ static xfCachedData* convert_data_from_existing_raw_data(xfClipboard* clipboard, return NULL; } - if (!HashTable_Insert(clipboard->cachedData, (void*)(UINT_PTR)dstFormatId, cached_data)) + if (!HashTable_Insert(clipboard->cachedData, format_to_cache_slot(dstFormatId), cached_data)) { WLog_WARN(TAG, "Failed to cache clipboard data"); xf_cached_data_free(cached_data); @@ -1547,11 +1558,11 @@ static BOOL xf_cliprdr_process_selection_request(xfClipboard* clipboard, DEBUG_CLIPRDR("formatId: %u, dstFormatId: %u", formatId, dstFormatId); if (!rawTransfer) - cached_data = - HashTable_GetItemValue(clipboard->cachedData, (void*)(UINT_PTR)dstFormatId); + cached_data = HashTable_GetItemValue(clipboard->cachedData, + format_to_cache_slot(dstFormatId)); else - cached_data = - HashTable_GetItemValue(clipboard->cachedRawData, (void*)(UINT_PTR)formatId); + cached_data = HashTable_GetItemValue(clipboard->cachedRawData, + format_to_cache_slot(formatId)); DEBUG_CLIPRDR("hasCachedData: %u, rawTransfer: %u", cached_data ? 1 : 0, rawTransfer); @@ -2290,7 +2301,8 @@ xf_cliprdr_server_format_data_response(CliprdrClientContext* context, free(pDstData); return CHANNEL_RC_OK; } - if (!HashTable_Insert(clipboard->cachedData, (void*)(UINT_PTR)dstFormatId, cached_data)) + if (!HashTable_Insert(clipboard->cachedData, format_to_cache_slot(dstFormatId), + cached_data)) { WLog_WARN(TAG, "Failed to cache clipboard data"); xf_cached_data_free(cached_data);