From 9f24a35c35bc943a84581aa44f8175ba1f11611b Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Tue, 6 Sep 2016 15:59:34 +0200 Subject: [PATCH] fixed copy to clipboard crash when there is nothing to copy --- src/editor/log_ui.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/editor/log_ui.cpp b/src/editor/log_ui.cpp index 2267583e0..562c2e2e7 100644 --- a/src/editor/log_ui.cpp +++ b/src/editor/log_ui.cpp @@ -204,20 +204,23 @@ void LogUI::onGUI() } } - char* mem = (char*)m_allocator.allocate(len); - mem[0] = '\0'; - for (int i = 0; i < messages->size(); ++i) + if (len > 0) { - const char* msg = (*messages)[i].c_str(); - if (filter[0] == '\0' || strstr(msg, filter) != nullptr) + char* mem = (char*)m_allocator.allocate(len); + mem[0] = '\0'; + for (int i = 0; i < messages->size(); ++i) { - Lumix::catString(mem, len, msg); - Lumix::catString(mem, len, "\n"); + const char* msg = (*messages)[i].c_str(); + if (filter[0] == '\0' || strstr(msg, filter) != nullptr) + { + Lumix::catString(mem, len, msg); + Lumix::catString(mem, len, "\n"); + } } - } - PlatformInterface::copyToClipboard(mem); - m_allocator.deallocate(mem); + PlatformInterface::copyToClipboard(mem); + m_allocator.deallocate(mem); + } } if (ImGui::BeginChild("log_messages"))