Skip to content

Commit 36054c4

Browse files
committed
Fix nlohmann#3513, explain is_ndarray flag
1 parent 41226d0 commit 36054c4

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

include/nlohmann/detail/input/binary_reader.hpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ class binary_reader
19381938
{
19391939
std::pair<std::size_t, char_int_type> size_and_type;
19401940
size_t dimlen = 0;
1941-
bool is_ndarray = true;
1941+
bool no_ndarray = true;
19421942

19431943
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
19441944
{
@@ -1953,7 +1953,7 @@ class binary_reader
19531953
{
19541954
for (std::size_t i = 0; i < size_and_type.first; ++i)
19551955
{
1956-
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, is_ndarray, size_and_type.second)))
1956+
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
19571957
{
19581958
return false;
19591959
}
@@ -1965,7 +1965,7 @@ class binary_reader
19651965
{
19661966
for (std::size_t i = 0; i < size_and_type.first; ++i)
19671967
{
1968-
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, is_ndarray)))
1968+
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
19691969
{
19701970
return false;
19711971
}
@@ -1977,7 +1977,7 @@ class binary_reader
19771977
{
19781978
while (current != ']')
19791979
{
1980-
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, is_ndarray, current)))
1980+
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
19811981
{
19821982
return false;
19831983
}
@@ -1990,6 +1990,12 @@ class binary_reader
19901990

19911991
/*!
19921992
@param[out] result determined size
1993+
@param[in,out] is_ndarray for input, `true` means already inside an ndarray vector
1994+
or ndarray dimension is not allowed; `false` means ndarray
1995+
is allowed; for output, `true` means an ndarray is found;
1996+
is_ndarray only returns true when its initial value is `false`
1997+
@param[in] prefix the previously read or set type prefix, read next if not given
1998+
19931999
@return whether size determination completed
19942000
*/
19952001
bool get_ubjson_size_value(std::size_t& result, bool& is_ndarray, char_int_type prefix = 0)
@@ -2640,8 +2646,8 @@ class binary_reader
26402646
{
26412647
// get size of following number string
26422648
std::size_t size{};
2643-
bool is_ndarray = false;
2644-
auto res = get_ubjson_size_value(size, is_ndarray);
2649+
bool no_ndarray = true;
2650+
auto res = get_ubjson_size_value(size, no_ndarray);
26452651
if (JSON_HEDLEY_UNLIKELY(!res))
26462652
{
26472653
return res;

single_include/nlohmann/json.hpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -10421,7 +10421,7 @@ class binary_reader
1042110421
{
1042210422
std::pair<std::size_t, char_int_type> size_and_type;
1042310423
size_t dimlen = 0;
10424-
bool is_ndarray = true;
10424+
bool no_ndarray = true;
1042510425

1042610426
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
1042710427
{
@@ -10436,7 +10436,7 @@ class binary_reader
1043610436
{
1043710437
for (std::size_t i = 0; i < size_and_type.first; ++i)
1043810438
{
10439-
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, is_ndarray, size_and_type.second)))
10439+
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
1044010440
{
1044110441
return false;
1044210442
}
@@ -10448,7 +10448,7 @@ class binary_reader
1044810448
{
1044910449
for (std::size_t i = 0; i < size_and_type.first; ++i)
1045010450
{
10451-
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, is_ndarray)))
10451+
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
1045210452
{
1045310453
return false;
1045410454
}
@@ -10460,7 +10460,7 @@ class binary_reader
1046010460
{
1046110461
while (current != ']')
1046210462
{
10463-
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, is_ndarray, current)))
10463+
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
1046410464
{
1046510465
return false;
1046610466
}
@@ -10473,6 +10473,12 @@ class binary_reader
1047310473

1047410474
/*!
1047510475
@param[out] result determined size
10476+
@param[in,out] is_ndarray for input, `true` means already inside an ndarray vector
10477+
or ndarray dimension is not allowed; `false` means ndarray
10478+
is allowed; for output, `true` means an ndarray is found;
10479+
is_ndarray only returns true when its initial value is `false`
10480+
@param[in] prefix the previously read or set type prefix, read next if not given
10481+
1047610482
@return whether size determination completed
1047710483
*/
1047810484
bool get_ubjson_size_value(std::size_t& result, bool& is_ndarray, char_int_type prefix = 0)
@@ -11123,8 +11129,8 @@ class binary_reader
1112311129
{
1112411130
// get size of following number string
1112511131
std::size_t size{};
11126-
bool is_ndarray = false;
11127-
auto res = get_ubjson_size_value(size, is_ndarray);
11132+
bool no_ndarray = true;
11133+
auto res = get_ubjson_size_value(size, no_ndarray);
1112811134
if (JSON_HEDLEY_UNLIKELY(!res))
1112911135
{
1113011136
return res;

0 commit comments

Comments
 (0)