From 3366ad4ed4fadbbf28600e887c6f12566e98d588 Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Tue, 25 Jan 2022 10:31:22 +0000 Subject: [PATCH] Linux: Avoid sending the string terminator to the X11 clipboard --- .../native/x11/juce_linux_XWindowSystem.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp index c0e7b8dc26..8e9a87d571 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp +++ b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp @@ -1351,20 +1351,22 @@ namespace ClipboardHelpers { auto localContent = XWindowSystem::getInstance()->getLocalClipboardContent(); - // translate to utf8 - numDataItems = localContent.getNumBytesAsUTF8() + 1; - data.calloc (numDataItems); - localContent.copyToUTF8 (data, numDataItems); - propertyFormat = 8; // bits/item + // Translate to utf8 + numDataItems = localContent.getNumBytesAsUTF8(); + auto numBytesRequiredToStore = numDataItems + 1; + data.calloc (numBytesRequiredToStore); + localContent.copyToUTF8 (data, numBytesRequiredToStore); + propertyFormat = 8; // bits per item } else if (evt.target == atoms.targets) { - // another application wants to know what we are able to send + // Another application wants to know what we are able to send + numDataItems = 2; - constexpr size_t atomSize = sizeof (Atom); - static_assert (atomSize == 8, "Atoms are 32-bit"); - propertyFormat = atomSize * 4; - data.calloc (numDataItems * atomSize); + data.calloc (numDataItems * sizeof (Atom)); + + // Atoms are flagged as 32-bit irrespective of sizeof (Atom) + propertyFormat = 32; auto* dataAtoms = unalignedPointerCast (data.getData()); @@ -1388,7 +1390,7 @@ namespace ClipboardHelpers { X11Symbols::getInstance()->xChangeProperty (evt.display, evt.requestor, evt.property, evt.target, - propertyFormat /* 8 or 32 */, PropModeReplace, + propertyFormat, PropModeReplace, reinterpret_cast (data.getData()), (int) numDataItems); reply.property = evt.property; // " == success" }