Skip to content

Commit

Permalink
fix nlohmann#1982: contains() exceptions are incorrectly raised
Browse files Browse the repository at this point in the history
  • Loading branch information
dota17 committed Mar 26, 2020
1 parent e07686f commit 1d7f337
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
22 changes: 17 additions & 5 deletions include/nlohmann/detail/json_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,26 @@ class json_pointer
return false;
}

const auto idx = static_cast<size_type>(array_index(reference_token));
if (idx >= ptr->size())
JSON_TRY
{
const auto idx = static_cast<size_type>(array_index(reference_token));
if (idx >= ptr->size())
{
// index out of range
return false;
}

ptr = &ptr->operator[](idx);
break;
}
JSON_CATCH(detail::parse_error&)
{
return false;
}
JSON_CATCH(detail::out_of_range&)
{
// index out of range
return false;
}

ptr = &ptr->operator[](idx);
break;
}

Expand Down
22 changes: 17 additions & 5 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10753,14 +10753,26 @@ class json_pointer
return false;
}

const auto idx = static_cast<size_type>(array_index(reference_token));
if (idx >= ptr->size())
JSON_TRY
{
const auto idx = static_cast<size_type>(array_index(reference_token));
if (idx >= ptr->size())
{
// index out of range
return false;
}

ptr = &ptr->operator[](idx);
break;
}
JSON_CATCH(detail::parse_error&)
{
return false;
}
JSON_CATCH(detail::out_of_range&)
{
// index out of range
return false;
}

ptr = &ptr->operator[](idx);
break;
}

Expand Down

0 comments on commit 1d7f337

Please sign in to comment.