From 0f9d90aa24d539e08b751fec6ea633c852fc7e17 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Sun, 2 Mar 2008 00:06:45 +0000 Subject: [PATCH] * This fixes ticket #1865 * Allocate the buffer to flatten the message on the heap, if it's size is bigger then a given buffer on the stack. It seem's to exceed the stack size (this might count for AddFlat() too). Note: With this change one is able to copy the text into the clipboard (1mb), but it is still impossible to paste it somewhere, as in BClipboard::_DownloadFromSystem() SendMessage() fails transferring the data back in the reply msg because of the port size limit... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24196 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/app/Message.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp index 8f04394afa..a5e4634edf 100644 --- a/src/kits/app/Message.cpp +++ b/src/kits/app/Message.cpp @@ -2300,13 +2300,25 @@ BMessage::AddMessage(const char *name, const BMessage *message) copying an extra buffer. Functions can be added that return a direct pointer into the message. */ + char buf[4096] = { 0 }; ssize_t size = message->FlattenedSize(); - char buffer[size]; + + bool freeBuffer = false; + char* buffer = NULL; + if (size > (ssize_t)sizeof(buffer)) { + freeBuffer = true; + buffer = static_cast(malloc(size)); + } else { + buffer = buf; + } status_t error = message->Flatten(buffer, size); if (error >= B_OK) - error = AddData(name, B_MESSAGE_TYPE, &buffer, size, false); + error = AddData(name, B_MESSAGE_TYPE, buffer, size, false); + + if (freeBuffer) + free(buffer); return error; }