Fix a scalar set() through a view of a value that an edit dropped
set(target, scalar) on an array/object that spans more than one node first switches the container that target is in to links, since that container steps over target's parsed subtree by its node count. The container was looked up from root(); for a target that is no longer part of the document (an edit erased or replaced it, or a value that contains it) the lookup found nothing and the scalar was written anyway. The dropped container then read past its nodes when walked, and a later edit of it made block_of() write more links than the block it allocated holds. When the lookup from root() fails, look for the container whose contiguous layout still steps over the slot: the nearest container before it in its allocation whose extent covers it (edits never enlarge an extent, so this is the original parent). If that container still uses its layout, it switches to links as a live parent does. Every other edit through a view of a dropped value already worked and changed only the detached value; the scalar set now does the same, as documented. Also stop block_of() when its block is full, so that it never writes past the capacity it allocated. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
6 files changed
+181
-8
No files matched your search
@@ -384,9 +384,22 @@ class editor
|
||||
// for the container is linear in the size of the document, so
|
||||
// links (which are marked in the slot) avoid it.
|
||||
node* const p = parent_known ? parent : find_parent(m_doc, slot);
|
||||
if (p != nullptr && ((p->flags & node_flags::moved) == 0 || moved_capacity(m_doc, p) == 0))
|
||||
if (p != nullptr)
|
||||
{
|
||||
block_of(m_doc, p, 0);
|
||||
if ((p->flags & node_flags::moved) == 0 || moved_capacity(m_doc, p) == 0)
|
||||
{
|
||||
block_of(m_doc, p, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// the slot is no longer part of the document, but the
|
||||
// (dropped) container it is in may still step over it
|
||||
node* const q = find_layout_parent(m_doc, slot);
|
||||
if (q != nullptr)
|
||||
{
|
||||
block_of(m_doc, q, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
*slot = e.scalar;
|
||||
|
||||
Reference in new issue
Block a user