Purge history on buffer reload when NoUndo flag is on

We were preserving the history in that case, so on fifo buffers
(that set the NoUndo flag until the fifo is closed), we still had
the history from the "previous life" of the buffer, leading crashes
when trying to apply it.

Fixes #1518
This commit is contained in:
Maxime Coste 2017-08-04 11:39:28 +07:00
parent 45a7496f54
commit fc64369f9d
3 changed files with 9 additions and 5 deletions

View File

@ -242,10 +242,13 @@ void Buffer::reload(StringView data, timespec fs_timestamp)
if (not record_undo)
{
// Erase history about to be invalidated history
m_history_cursor = &m_history;
m_last_save_history_cursor = &m_history;
m_history = HistoryNode{m_next_history_id++, nullptr};
m_changes.push_back({ Change::Erase, {0,0}, line_count() });
static_cast<BufferLines&>(m_lines) = std::move(parsed_lines.lines);
m_changes.push_back({ Change::Insert, {0,0}, line_count() });
}
else
@ -340,7 +343,7 @@ bool Buffer::redo(size_t count) noexcept
while (count-- != 0 and m_history_cursor->redo_child)
{
m_history_cursor = m_history_cursor->redo_child.get();
m_history_cursor = m_history_cursor->redo_child;
for (const Modification& modification : m_history_cursor->undo_group)
apply_modification(modification);

View File

@ -252,14 +252,14 @@ private:
using UndoGroup = Vector<Modification, MemoryDomain::BufferMeta>;
struct HistoryNode : SafeCountable, UseMemoryDomain<MemoryDomain::BufferMeta>
struct HistoryNode : SafeCountable, UseMemoryDomain<MemoryDomain::BufferMeta>
{
HistoryNode(size_t id, HistoryNode* parent);
UndoGroup undo_group;
Vector<std::unique_ptr<HistoryNode>, MemoryDomain::BufferMeta> childs;
SafePtr<HistoryNode> parent;
SafePtr<HistoryNode> redo_child;
HistoryNode* redo_child = nullptr; // not a SafePtr to avoid lifetime issues between this and childs
size_t id;
TimePoint timepoint;
};

View File

@ -0,0 +1 @@
<a-O>ifoo<c-u><esc>:edit -fifo /dev/null <c-r>%<ret>u