Skip to content

Commit f9eb241

Browse files
committed
Merge branch 'nlohmann:develop' into develop
2 parents 2d04d40 + 4f64d8d commit f9eb241

File tree

6 files changed

+53
-43
lines changed

6 files changed

+53
-43
lines changed

cmake/ci.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ add_custom_target(ci_test_diagnostic_positions
562562
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics_positions
563563
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_diagnostics_positions
564564
COMMAND cd ${PROJECT_BINARY_DIR}/build_diagnostics_positions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
565-
COMMENT "Compile and test with improved diagnostics positions enabled"
565+
COMMENT "Compile and test with diagnostics positions enabled"
566566
)
567567

568568
###############################################################################

include/nlohmann/detail/input/binary_reader.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class binary_reader
172172
std::int32_t document_size{};
173173
get_number<std::int32_t, true>(input_format_t::bson, document_size);
174174

175-
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
175+
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
176176
{
177177
return false;
178178
}
@@ -394,7 +394,7 @@ class binary_reader
394394
std::int32_t document_size{};
395395
get_number<std::int32_t, true>(input_format_t::bson, document_size);
396396

397-
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))
397+
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
398398
{
399399
return false;
400400
}
@@ -654,7 +654,7 @@ class binary_reader
654654
}
655655

656656
case 0x9F: // array (indefinite length)
657-
return get_cbor_array(static_cast<std::size_t>(-1), tag_handler);
657+
return get_cbor_array(detail::unknown_size(), tag_handler);
658658

659659
// map (0x00..0x17 pairs of data items follow)
660660
case 0xA0:
@@ -708,7 +708,7 @@ class binary_reader
708708
}
709709

710710
case 0xBF: // map (indefinite length)
711-
return get_cbor_object(static_cast<std::size_t>(-1), tag_handler);
711+
return get_cbor_object(detail::unknown_size(), tag_handler);
712712

713713
case 0xC6: // tagged item
714714
case 0xC7:
@@ -1096,7 +1096,7 @@ class binary_reader
10961096
}
10971097

10981098
/*!
1099-
@param[in] len the length of the array or static_cast<std::size_t>(-1) for an
1099+
@param[in] len the length of the array or detail::unknown_size() for an
11001100
array of indefinite size
11011101
@param[in] tag_handler how CBOR tags should be treated
11021102
@return whether array creation completed
@@ -1109,7 +1109,7 @@ class binary_reader
11091109
return false;
11101110
}
11111111

1112-
if (len != static_cast<std::size_t>(-1))
1112+
if (len != detail::unknown_size())
11131113
{
11141114
for (std::size_t i = 0; i < len; ++i)
11151115
{
@@ -1134,7 +1134,7 @@ class binary_reader
11341134
}
11351135

11361136
/*!
1137-
@param[in] len the length of the object or static_cast<std::size_t>(-1) for an
1137+
@param[in] len the length of the object or detail::unknown_size() for an
11381138
object of indefinite size
11391139
@param[in] tag_handler how CBOR tags should be treated
11401140
@return whether object creation completed
@@ -1150,7 +1150,7 @@ class binary_reader
11501150
if (len != 0)
11511151
{
11521152
string_t key;
1153-
if (len != static_cast<std::size_t>(-1))
1153+
if (len != detail::unknown_size())
11541154
{
11551155
for (std::size_t i = 0; i < len; ++i)
11561156
{
@@ -2568,7 +2568,7 @@ class binary_reader
25682568
}
25692569
else
25702570
{
2571-
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))
2571+
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
25722572
{
25732573
return false;
25742574
}
@@ -2646,7 +2646,7 @@ class binary_reader
26462646
}
26472647
else
26482648
{
2649-
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
2649+
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
26502650
{
26512651
return false;
26522652
}
@@ -2982,7 +2982,7 @@ class binary_reader
29822982
}
29832983

29842984
private:
2985-
static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast<std::size_t>(-1);
2985+
static JSON_INLINE_VARIABLE constexpr std::size_t npos = detail::unknown_size();
29862986

29872987
/// input adapter
29882988
InputAdapterType ia;

include/nlohmann/detail/input/json_sax.hpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ struct json_sax
145145

146146
namespace detail
147147
{
148+
constexpr std::size_t unknown_size()
149+
{
150+
return (std::numeric_limits<std::size_t>::max)();
151+
}
152+
148153
/*!
149154
@brief SAX implementation to create a JSON value from SAX events
150155
@@ -242,7 +247,7 @@ class json_sax_dom_parser
242247
}
243248
#endif
244249

245-
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
250+
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
246251
{
247252
JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back()));
248253
}
@@ -291,7 +296,7 @@ class json_sax_dom_parser
291296
}
292297
#endif
293298

294-
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
299+
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
295300
{
296301
JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back()));
297302
}
@@ -559,7 +564,7 @@ class json_sax_dom_callback_parser
559564
#endif
560565

561566
// check object limit
562-
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
567+
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
563568
{
564569
JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back()));
565570
}
@@ -657,7 +662,7 @@ class json_sax_dom_callback_parser
657662
#endif
658663

659664
// check array limit
660-
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
665+
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
661666
{
662667
JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back()));
663668
}
@@ -946,7 +951,7 @@ class json_sax_acceptor
946951
return true;
947952
}
948953

949-
bool start_object(std::size_t /*unused*/ = static_cast<std::size_t>(-1))
954+
bool start_object(std::size_t /*unused*/ = detail::unknown_size())
950955
{
951956
return true;
952957
}
@@ -961,7 +966,7 @@ class json_sax_acceptor
961966
return true;
962967
}
963968

964-
bool start_array(std::size_t /*unused*/ = static_cast<std::size_t>(-1))
969+
bool start_array(std::size_t /*unused*/ = detail::unknown_size())
965970
{
966971
return true;
967972
}

include/nlohmann/detail/input/parser.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class parser
194194
{
195195
case token_type::begin_object:
196196
{
197-
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
197+
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
198198
{
199199
return false;
200200
}
@@ -239,7 +239,7 @@ class parser
239239

240240
case token_type::begin_array:
241241
{
242-
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))
242+
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
243243
{
244244
return false;
245245
}

include/nlohmann/json.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
751751
return it;
752752
}
753753

754-
reference set_parent(reference j, std::size_t old_capacity = static_cast<std::size_t>(-1))
754+
reference set_parent(reference j, std::size_t old_capacity = detail::unknown_size())
755755
{
756756
#if JSON_DIAGNOSTICS
757-
if (old_capacity != static_cast<std::size_t>(-1))
757+
if (old_capacity != detail::unknown_size())
758758
{
759759
// see https://github.com/nlohmann/json/issues/2838
760760
JSON_ASSERT(type() == value_t::array);

0 commit comments

Comments
 (0)