mirror of
https://github.com/nlohmann/json.git
synced 2026-10-11 00:47:12 +00:00
Read the node array base after emit() in the view builder's open()
emit() moves the node array when it grows, and the subtraction read base in the same expression, so the order was unspecified. MSVC Release builds without forced inlining read the old base; the container index then pointed outside the array and close() wrote out of bounds. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
2 files changed
+8
-2
No files matched your search
@@ -821,7 +821,10 @@ indent_done:
|
||||
|
||||
NLOHMANN_VIEW_ALWAYS_INLINE void open(value_t k)
|
||||
{
|
||||
const auto idx = static_cast<std::uint32_t>(emit(k, 0, 0, static_cast<std::size_t>(p - b), 0) - base);
|
||||
// (base is read after emit(), which moves the node array when it
|
||||
// grows; in one expression the order of the two is unspecified)
|
||||
const node* const n = emit(k, 0, 0, static_cast<std::size_t>(p - b), 0);
|
||||
const auto idx = static_cast<std::uint32_t>(n - base);
|
||||
if (depth != 0)
|
||||
{
|
||||
const frame f = {cur_idx, cur_count, cur_is_object};
|
||||
|
||||
@@ -1420,7 +1420,10 @@ indent_done:
|
||||
|
||||
NLOHMANN_VIEW_ALWAYS_INLINE void open(value_t k)
|
||||
{
|
||||
const auto idx = static_cast<std::uint32_t>(emit(k, 0, 0, static_cast<std::size_t>(p - b), 0) - base);
|
||||
// (base is read after emit(), which moves the node array when it
|
||||
// grows; in one expression the order of the two is unspecified)
|
||||
const node* const n = emit(k, 0, 0, static_cast<std::size_t>(p - b), 0);
|
||||
const auto idx = static_cast<std::uint32_t>(n - base);
|
||||
if (depth != 0)
|
||||
{
|
||||
const frame f = {cur_idx, cur_count, cur_is_object};
|
||||
|
||||
Reference in new issue
Block a user