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
This commit is contained in:
Michael Lotz 2006-04-11 23:01:32 +00:00
parent f775a1fea7
commit eef8149582

View File

@ -1379,8 +1379,8 @@ BMessage::_ResizeData(int32 offset, int32 change)
if (change > 0) { if (change > 0) {
if (fHeader->data_available >= change) { if (fHeader->data_available >= change) {
if (offset < fHeader->data_size) { if (offset < fHeader->data_size) {
ssize_t length = fHeader->data_size - offset; memmove(fData + offset + change, fData + offset,
memmove(fData + offset + change, fData + offset, length); fHeader->data_size - offset);
} }
fHeader->data_available -= change; fHeader->data_available -= change;
@ -1398,14 +1398,16 @@ BMessage::_ResizeData(int32 offset, int32 change)
if (offset < fHeader->data_size) { if (offset < fHeader->data_size) {
memmove(fData + offset + change, fData + offset, memmove(fData + offset + change, fData + offset,
fHeader->data_size - offset - change); fHeader->data_size - offset);
} }
fHeader->data_size += change; fHeader->data_size += change;
fHeader->data_available = size - fHeader->data_size; fHeader->data_available = size - fHeader->data_size;
} else { } else {
ssize_t size = fHeader->data_size; ssize_t length = fHeader->data_size - offset + change;
memmove(fData + offset, fData + offset - change, size - offset + change); if (length > 0)
memmove(fData + offset, fData + offset - change, length);
fHeader->data_size += change; fHeader->data_size += change;
fHeader->data_available -= change; fHeader->data_available -= change;