Use unsigned indizies for array index in json pointer#2203
Merged
nlohmann merged 2 commits intonlohmann:developfrom Jun 23, 2020
Merged
Conversation
Forgotten in dcd3a6c (move the catch of std::invalid_argument into array_index(), 2020-03-23).
6580e3e to
54a3988
Compare
nlohmann
reviewed
Jun 20, 2020
nlohmann
requested changes
Jun 21, 2020
fed4474 to
7807a43
Compare
Contributor
Author
|
@nlohmann The coverage decreased because that code only triggers when sizeof(size_type) < sizeof(unsigned long long) (aka 32bit) and it looks like coverage is calculated for 64-bit. |
Owner
|
I see. I tried to build a 32 bit binary, but the CI seems not to support this. Could you add a comment before the |
…en parsing The current code uses std::stoi to convert the input string to an int array_index. This limits the maximum addressable array size to ~2GB on most platforms. But all callers immediately convert the result of array_index to BasicJsonType::size_type. So let's parse it as unsigned long long, which allows us to have as big arrays as available memory. And also makes the call sites nicer to read. One complication arises on platforms where size_type is smaller than unsigned long long. We need to bail out on these if the parsed array index does not fit into size_type.
7807a43 to
ecbb275
Compare
Contributor
Author
|
@nlohmann Done. |
Owner
|
Thanks a lot! |
Owner
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
This was referenced Jun 27, 2020
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current code uses std::stoi to convert the input string to an int
array_index. This limits the maximum addressable array size to ~2GB on most
platforms.
But all callers immediately convert the result of array_index to
BasicJsonType::size_type.
So let's parse it as unsigned long long, which allows us to have as big arrays
as available memory. And also makes the call sites nicer to read.