mirror of
https://github.com/nlohmann/json.git
synced 2026-11-17 09:01:28 +00:00
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>