mirror of
https://github.com/nlohmann/json.git
synced 2026-11-13 15:35:23 +00:00
The seven serializer helpers marked JSON_HEDLEY_ALWAYS_INLINE are inlined at -O0 as well, and GCC and Clang give every inlined copy its own stack slots there. That made the recursive frame of dump_container() 2304 bytes with Clang 21 (2048 with GCC 16), against 480 bytes in 3.12.0, so dump() of a value nested beyond the default recursion depth limit needed 288 KiB of stack in an unoptimized build and crashed in a 128 KiB musl thread. Define JSON_INTERNAL_SERIALIZER_INLINE as JSON_HEDLEY_ALWAYS_INLINE when __OPTIMIZE__ (or _MSC_VER) is defined and as plain inline otherwise, and use it for these helpers. The frame drops to 320 bytes and dump() needs 48 KiB at the default limit. The -O2 object code is unchanged with Clang 21 and GCC 16. Update the stack tables in json_recursion_depth_limit.md and untrusted_input.md: copying and conversion are now the most demanding operations at -O0. Fixes #6116. Signed-off-by: Niels Lohmann <mail@nlohmann.me>