LibGUI: Don't crash if calling GClipboard::set_data() with a null string.

This commit is contained in:
Andreas Kling 2019-03-18 02:59:08 +01:00
parent ce7017e1ec
commit 77a782a67e
Notes: sideshowbarker 2024-07-19 15:01:10 +09:00

View file

@ -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();