From 5a0ec6e1989d1167e0d0872667c28cde002e2908 Mon Sep 17 00:00:00 2001 From: Twice Date: Thu, 3 Oct 2024 11:44:58 +0800 Subject: [PATCH] Avoid integer overflow UB in basic_json_parser --- include/jsoncons/json_parser.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/jsoncons/json_parser.hpp b/include/jsoncons/json_parser.hpp index a7efe13b0..3b9855fce 100644 --- a/include/jsoncons/json_parser.hpp +++ b/include/jsoncons/json_parser.hpp @@ -177,7 +177,7 @@ class basic_json_parser : public ser_context { string_buffer_.reserve(initial_string_buffer_capacity); - std::size_t initial_stack_capacity = (options.max_nesting_depth()+2) <= default_initial_stack_capacity ? (options.max_nesting_depth()+2) : default_initial_stack_capacity; + std::size_t initial_stack_capacity = options.max_nesting_depth() <= (default_initial_stack_capacity-2) ? (options.max_nesting_depth()+2) : default_initial_stack_capacity; state_stack_.reserve(initial_stack_capacity ); push_state(json_parse_state::root);