From 73c630c94846ea0738cf3e37eee2c25c89b73045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 16 Jan 2004 04:57:20 +0000 Subject: [PATCH] The DataChange constructor must no longer make any changes to the buffer. DataChange::Apply() will now remember the string instead, so that undo/redo will work correctly even if the underlying data has changed in the mean time. DataEditor::AddChange() will now apply the change as well. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6103 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/DataEditor.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/apps/diskprobe/DataEditor.cpp b/src/apps/diskprobe/DataEditor.cpp index 9731f386c6..b80dd9ab95 100644 --- a/src/apps/diskprobe/DataEditor.cpp +++ b/src/apps/diskprobe/DataEditor.cpp @@ -54,13 +54,7 @@ ReplaceChange::ReplaceChange(off_t bufferOffset, uint8 *buffer, fNewData = (uint8 *)malloc(size); fOldData = (uint8 *)malloc(size); if (fNewData != NULL && fOldData != NULL) { - // Save old data, and replace the data in the supplied buffer. - // Note, the buffer must be large enough to hold the changes - // at this point! memcpy(fNewData, data, size); - memcpy(fOldData, buffer + offset - bufferOffset, size); - memcpy(buffer + offset - bufferOffset, fNewData, size); - fSize = size; } else fSize = 0; @@ -110,7 +104,8 @@ ReplaceChange::Apply(off_t bufferOffset, uint8 *buffer, size_t bufferSize) if (size == 0) return; - // now we can safely change the buffer! + // now we can safely exchange the buffer! + memcpy(fOldData + dataOffset, buffer + offset - bufferOffset, size); memcpy(buffer + offset - bufferOffset, fNewData + dataOffset, size); } @@ -252,6 +247,8 @@ DataEditor::AddChange(DataChange *change) fChanges.AddItem(change); fLastChange = change; + + fLastChange->Apply(fRealViewOffset, fView, fRealViewSize); }