summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2023-05-13 08:51:05 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-13 10:19:28 +0200
commit2626136749a8f389b2971f949dd39bb8843581e1 (patch)
tree5a31ed237eeec29a28638358f240a8809107f282 /Userland/Services
parent9d78619b595d885fb7389e3d969203d8cf2719bf (diff)
downloadserenity-2626136749a8f389b2971f949dd39bb8843581e1.zip
SpiceAgent: Gracefully handle the host clearing the clipboard
When the host clears the clipboard (e.g. by running `pbcopy </dev/null`) the Spice server sends an empty string to us. Previously, we would crash as `AnonymousBuffer::create_with_size` doesn't accept a size of 0. Fix this by passing `{}` to `async_set_clipboard_data` in this case.
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/SpiceAgent/SpiceAgent.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/Userland/Services/SpiceAgent/SpiceAgent.cpp b/Userland/Services/SpiceAgent/SpiceAgent.cpp
index 0d74286a5b..86e960e32f 100644
--- a/Userland/Services/SpiceAgent/SpiceAgent.cpp
+++ b/Userland/Services/SpiceAgent/SpiceAgent.cpp
@@ -132,11 +132,15 @@ void SpiceAgent::on_message_received()
m_just_set_clip = true;
if (type == ClipboardType::Text) {
- auto anon_buffer_or_error = Core::AnonymousBuffer::create_with_size(data_buffer.size());
- VERIFY(!anon_buffer_or_error.is_error());
- auto anon_buffer = anon_buffer_or_error.release_value();
- memcpy(anon_buffer.data<void>(), data_buffer.data(), data_buffer.size());
- m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {});
+ if (data_buffer.is_empty()) {
+ m_clipboard_connection.async_set_clipboard_data({}, "text/plain", {});
+ } else {
+ auto anon_buffer_or_error = Core::AnonymousBuffer::create_with_size(data_buffer.size());
+ VERIFY(!anon_buffer_or_error.is_error());
+ auto anon_buffer = anon_buffer_or_error.release_value();
+ memcpy(anon_buffer.data<void>(), data_buffer.data(), data_buffer.size());
+ m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {});
+ }
return;
} else {
ErrorOr<Gfx::ImageFrameDescriptor> frame_or_error = Gfx::ImageFrameDescriptor {};