mirror of
https://github.com/nlohmann/json.git
synced 2026-11-02 19:05:35 +00:00
Guard the null value of a value-initialized iterator; drop the unneeded found flag
With the root's byte range, diagnostics() reaches get_byte_positions() also with JSON_DIAGNOSTICS when there is no value, as for a value-initialized iterator (invalid_iterator.212). get_byte_positions() now returns no range for a null value, the same change as #6003, so either can be merged first. In the view, a value that value_path() does not find leaves no tokens, so the found flag added nothing to the tokens.empty() test. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
5 files changed
+21
-6
No files matched your search
@@ -265,3 +265,14 @@ TEST_CASE("values read from a binary format have no positions")
|
||||
check_no_positions(j);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("comparing a value-initialized iterator throws invalid_iterator.212")
|
||||
{
|
||||
// such an iterator has no value to take the byte positions from; the
|
||||
// comparison used to dereference the null pointer instead of throwing
|
||||
json j = {1, 2};
|
||||
json::iterator it{};
|
||||
CHECK_THROWS_WITH_AS(it == j.begin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator);
|
||||
CHECK_THROWS_WITH_AS(it < j.begin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator);
|
||||
CHECK_THROWS_WITH_AS(j.begin() == it, "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator);
|
||||
}
|
||||
Reference in new issue
Block a user