mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
Fix nlohmann/json#3513, explain is_ndarray flag (#3514)
* Fix nlohmann/json#3513, explain is_ndarray flag * add test for ndarray size following H
This commit is contained in:
@ -10528,9 +10528,9 @@ class binary_reader
|
||||
{
|
||||
std::pair<std::size_t, char_int_type> size_and_type;
|
||||
size_t dimlen = 0;
|
||||
bool inside_ndarray = true;
|
||||
bool no_ndarray = true;
|
||||
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, inside_ndarray)))
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -10543,7 +10543,7 @@ class binary_reader
|
||||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, inside_ndarray, size_and_type.second)))
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -10555,7 +10555,7 @@ class binary_reader
|
||||
{
|
||||
for (std::size_t i = 0; i < size_and_type.first; ++i)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, inside_ndarray)))
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -10567,7 +10567,7 @@ class binary_reader
|
||||
{
|
||||
while (current != ']')
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, inside_ndarray, current)))
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -10580,12 +10580,16 @@ class binary_reader
|
||||
|
||||
/*!
|
||||
@param[out] result determined size
|
||||
@param[in,out] inside_ndarray whether the parser is parsing an ND array dimensional vector
|
||||
@param[in,out] is_ndarray for input, `true` means already inside an ndarray vector
|
||||
or ndarray dimension is not allowed; `false` means ndarray
|
||||
is allowed; for output, `true` means an ndarray is found;
|
||||
is_ndarray can only return `true` when its initial value
|
||||
is `false`
|
||||
@param[in] prefix type marker if already read, otherwise set to 0
|
||||
|
||||
@return whether size determination completed
|
||||
*/
|
||||
bool get_ubjson_size_value(std::size_t& result, bool& inside_ndarray, char_int_type prefix = 0)
|
||||
bool get_ubjson_size_value(std::size_t& result, bool& is_ndarray, char_int_type prefix = 0)
|
||||
{
|
||||
if (prefix == 0)
|
||||
{
|
||||
@ -10720,9 +10724,9 @@ class binary_reader
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (inside_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array
|
||||
if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array
|
||||
{
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimention vector can only contain integers", "size"), nullptr));
|
||||
return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimentional vector is not allowed", "size"), nullptr));
|
||||
}
|
||||
std::vector<size_t> dim;
|
||||
if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
|
||||
@ -10759,7 +10763,7 @@ class binary_reader
|
||||
return false;
|
||||
}
|
||||
}
|
||||
inside_ndarray = true;
|
||||
is_ndarray = true;
|
||||
return sax->end_array();
|
||||
}
|
||||
result = 0;
|
||||
@ -11240,8 +11244,8 @@ class binary_reader
|
||||
{
|
||||
// get size of following number string
|
||||
std::size_t size{};
|
||||
bool inside_ndarray = false;
|
||||
auto res = get_ubjson_size_value(size, inside_ndarray);
|
||||
bool no_ndarray = true;
|
||||
auto res = get_ubjson_size_value(size, no_ndarray);
|
||||
if (JSON_HEDLEY_UNLIKELY(!res))
|
||||
{
|
||||
return res;
|
||||
|
Reference in New Issue
Block a user