-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use unsigned indizies for array index in json pointer #2203
Use unsigned indizies for array index in json pointer #2203
Conversation
Forgotten in dcd3a6c (move the catch of std::invalid_argument into array_index(), 2020-03-23).
6580e3e
to
54a3988
Compare
fed4474
to
7807a43
Compare
@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. |
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
@nlohmann Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Thanks a lot! |
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
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.