From eef81495829519b42379c28e137c53fc2490f01b Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Tue, 11 Apr 2006 23:01:32 +0000 Subject: [PATCH] Fixed wrong length calculation for memmove. This should at least fix bug #314 and probably more yet unknown problems with ReplaceData(). Also optimized removing data from the end of the buffer. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17101 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/app/Message.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp index db17285301..aa2b089e6c 100644 --- a/src/kits/app/Message.cpp +++ b/src/kits/app/Message.cpp @@ -1379,8 +1379,8 @@ BMessage::_ResizeData(int32 offset, int32 change) if (change > 0) { if (fHeader->data_available >= change) { if (offset < fHeader->data_size) { - ssize_t length = fHeader->data_size - offset; - memmove(fData + offset + change, fData + offset, length); + memmove(fData + offset + change, fData + offset, + fHeader->data_size - offset); } fHeader->data_available -= change; @@ -1398,14 +1398,16 @@ BMessage::_ResizeData(int32 offset, int32 change) if (offset < fHeader->data_size) { memmove(fData + offset + change, fData + offset, - fHeader->data_size - offset - change); + fHeader->data_size - offset); } fHeader->data_size += change; fHeader->data_available = size - fHeader->data_size; } else { - ssize_t size = fHeader->data_size; - memmove(fData + offset, fData + offset - change, size - offset + change); + ssize_t length = fHeader->data_size - offset + change; + if (length > 0) + memmove(fData + offset, fData + offset - change, length); + fHeader->data_size += change; fHeader->data_available -= change;