Fix int64 min issue#1722
Merged
Merged
Conversation
Contributor
|
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++. |
Contributor
|
Maybe you could do something like |
3dbaa54 to
e8ab305
Compare
Contributor
Author
|
@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. |
jaredgrubb
reviewed
Aug 26, 2019
8ed16e2 to
cc79e66
Compare
cc79e66 to
4b17347
Compare
nlohmann
requested changes
Sep 2, 2019
Owner
nlohmann
left a comment
There was a problem hiding this comment.
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
Contributor
Author
|
@nlohmann Thanks for the review. |
Owner
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
Owner
|
Thanks a lot! |
dnsmichi
pushed a commit
to Icinga/icinga2
that referenced
this pull request
Dec 13, 2019
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 was referenced Dec 13, 2019
Al2Klimov
pushed a commit
to Icinga/icinga2
that referenced
this pull request
Dec 16, 2019
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
N-o-X
pushed a commit
to Icinga/icinga2
that referenced
this pull request
May 8, 2020
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 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.
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?