From 4e0e915b131f4e7afb38506c237ec31172e99af6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 20 Oct 2026 22:26:00 +0200 Subject: [PATCH] Bind the serializer's frame only after the check for its end Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/serializer.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/nlohmann/detail/view/serializer.hpp b/include/nlohmann/detail/view/serializer.hpp index d450ecfd3..a800a7953 100644 --- a/include/nlohmann/detail/view/serializer.hpp +++ b/include/nlohmann/detail/view/serializer.hpp @@ -174,15 +174,15 @@ class view_serializer m_out.finish(); return; } - frame& f = stack.back(); - if (f.pos == f.end) + if (stack.back().pos == stack.back().end) { - const bool object = f.object; // (f dangles after pop_back) + const bool object = stack.back().object; stack.pop_back(); newline(stack.size()); m_out.put(object ? '}' : ']'); continue; } + frame& f = stack.back(); if (!f.first) { m_out.put(',');