You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const auto idx = json_pointer::array_index(last_path);
if (JSON_HEDLEY_UNLIKELY(static_cast<size_type>(idx) > parent.size()))
{
// avoid undefined behavior
JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range"));
}
// default case: insert add offset
and I'm really not understanding why it is if (JSON_HEDLEY_UNLIKELY(static_cast<size_type>(idx) > parent.size())) and not if (JSON_HEDLEY_UNLIKELY(static_cast<size_type>(idx) >= parent.size())). For zero-based indizes we need to be smaller than the size or?
The text was updated successfully, but these errors were encountered:
The specified index MUST NOT be greater than the number of elements in the array. If the "-" character is used to index the end of the array (see [RFC6901]), this has the effect of appending the value to the array.
I interpret these sentences that (1) passing the size of the array as index is allowed (as that index is not greater than the number of elements) and that (2) that value could be interpreted just like -, meaning we would append to the array.
Just for future reference: In your example (parent.begin() + static_cast<difference_type>(idx)) == parent.end() holds and parent.end() can be passed to insert.
Due to my work on #2203 I stumpled upon:
json/single_include/nlohmann/json.hpp
Lines 24000 to 24010 in 29ad217
and I'm really not understanding why it is
if (JSON_HEDLEY_UNLIKELY(static_cast<size_type>(idx) > parent.size()))
and notif (JSON_HEDLEY_UNLIKELY(static_cast<size_type>(idx) >= parent.size()))
. For zero-based indizes we need to be smaller than the size or?The text was updated successfully, but these errors were encountered: