-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Fix int64 min issue #1722
Fix int64 min issue #1722
Conversation
This patch invokes Undefined Behavior. You aren't allowed to take the negative of "min int". Eg, for Int8, the negative of -128 is +128, which is not representable in Int8. This is UB in C++. |
Maybe you could do something like |
3dbaa54
to
e8ab305
Compare
@jaredgrubb Thanks for the review. Good point. Your suggestion is pretty close to the old solution prior to 546e2cb. I've used that one, but also moved the code into functions to avoid the warning which 546e2cb wanted to fix. Let's see what CI says. |
8ed16e2
to
cc79e66
Compare
cc79e66
to
4b17347
Compare
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.
I have some minor change requests.
For some gcc version (Ubuntu 5.5.0-12ubuntu1~16.04) the existing code crashes when the minimum value of int64_t is outputted. Resurrect the code from before 546e2cb (:rotating_light: fixed some warnings, 2019-03-13) but delegate the sign removal so that the compilers don't complain about taking the negative value of an unsigned value. In addition we also rewrite the expression so that we first increment and then negate. The definition of remove_sign(number_unsigned_t) is never called as unsigned values are never negative.
4b17347
to
8067c3c
Compare
@nlohmann Thanks for the review. |
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.
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
Thanks a lot! |
This includes the following fixes: nlohmann/json#1436 > For a deeply-nested JSON object, the recursive implementation of json_value::destroy function causes stack overflow. nlohmann/json#1708 nlohmann/json#1722 Stack size nlohmann/json#1693 (comment) Integer Overflow nlohmann/json#1447 UTF8, json dump out of bounds nlohmann/json#1445 Possibly influences #7532
This includes the following fixes: nlohmann/json#1436 > For a deeply-nested JSON object, the recursive implementation of json_value::destroy function causes stack overflow. nlohmann/json#1708 nlohmann/json#1722 Stack size nlohmann/json#1693 (comment) Integer Overflow nlohmann/json#1447 UTF8, json dump out of bounds nlohmann/json#1445 Possibly influences #7532
This includes the following fixes: nlohmann/json#1436 > For a deeply-nested JSON object, the recursive implementation of json_value::destroy function causes stack overflow. nlohmann/json#1708 nlohmann/json#1722 Stack size nlohmann/json#1693 (comment) Integer Overflow nlohmann/json#1447 UTF8, json dump out of bounds nlohmann/json#1445 Possibly influences #7532
Close #1708.
For some gcc version (Ubuntu 5.5.0-12ubuntu1~16.04) the existing code
crashes when the minimum value of int64_t is outputted.
Rewrite the code to be less complicated to avoid it. This partially
reverts what was done in 546e2cb (rotating_light fixed some warnings,
2019-03-13).
It might be the case that this reintroduces the warning removed earlier. If that is the case, I will rewrite the code using templates to conditionally remove the sign for the negative case only.
Do we need static assertions which ensure that every positive number_integer_t fits into a number_unsigned_t?