From 77a782a67eca62e838e42172f2fce8bbc01fe3a6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 18 Mar 2019 02:59:08 +0100 Subject: [PATCH] LibGUI: Don't crash if calling GClipboard::set_data() with a null string. --- LibGUI/GClipboard.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/LibGUI/GClipboard.cpp b/LibGUI/GClipboard.cpp index 01e198b1ffc..d6fe9efba33 100644 --- a/LibGUI/GClipboard.cpp +++ b/LibGUI/GClipboard.cpp @@ -43,7 +43,10 @@ void GClipboard::set_data(const String& data) dbgprintf("GClipboard::set_data() failed to create a shared buffer\n"); return; } - memcpy(shared_buffer->data(), data.characters(), data.length() + 1); + if (!data.is_empty()) + memcpy(shared_buffer->data(), data.characters(), data.length() + 1); + else + ((byte*)shared_buffer->data())[0] = '\0'; shared_buffer->seal(); request.clipboard.shared_buffer_id = shared_buffer->shared_buffer_id(); request.clipboard.contents_size = data.length();