mirror of
https://github.com/nlohmann/json.git
synced 2026-09-29 11:10:30 +00:00
dump() and hash() each defined their own limit on how many nesting levels they recurse into, and the operations still to come would have added more, free to diverge over time. They now all use detail::recursion_depth_limit(), in a header of its own; serializer::dump_depth_limit() and hash_depth_limit() are gone. hash_iteratively() now copies the frame it works on out of the stack and changes the frame only through stack.back(), so nothing can refer into the stack after entering an element has grown it. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
36 lines
987 B
C++
36 lines
987 B
C++
// __ _____ _____ _____
|
|
// __| | __| | | | JSON for Modern C++
|
|
// | | |__ | | | | | | version 3.12.0
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
//
|
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef> // size_t
|
|
|
|
#include <nlohmann/detail/abi_macros.hpp>
|
|
|
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
|
namespace detail
|
|
{
|
|
|
|
/*!
|
|
@brief the number of nesting levels an operation recurses into
|
|
|
|
Operations that walk a value (serializing, hashing, merging, ...) recurse once
|
|
per nesting level, which is fastest, but a value nested deeply enough would
|
|
exhaust the call stack. So they recurse only this many levels deep and finish
|
|
whatever lies below with an explicit stack. All of them share this limit.
|
|
|
|
@sa https://github.com/nlohmann/json/issues/5387
|
|
*/
|
|
constexpr std::size_t recursion_depth_limit() noexcept
|
|
{
|
|
return 128;
|
|
}
|
|
|
|
} // namespace detail
|
|
NLOHMANN_JSON_NAMESPACE_END
|