Properly stringify both large and small int64's when converting to json#1060
Merged
Properly stringify both large and small int64's when converting to json#1060
Conversation
heifner
reviewed
Apr 20, 2023
libraries/libfc/src/io/json.cpp
Outdated
| int64_t i = v.as_int64(); | ||
| if( format == json::output_formatting::stringify_large_ints_and_doubles && | ||
| i > 0xffffffff ) | ||
| (i * ((i>0)-(i<0)) > 0xffffffff)) |
Contributor
There was a problem hiding this comment.
I find this construct rather odd and I am a bit surprised that compilers would not give a warning about bool used in arithmetic statement.
Seems like: (i > 0xffffffff) || (i < -0xffffffff) would be clearer.
Contributor
There was a problem hiding this comment.
how about std::abs(i) > 0xffffffff
probably cmath should be included
There was a problem hiding this comment.
Casting to uint64_t should also do the job, i.e. static_cast<uint64_t>(i) > 0xffffffff
Contributor
Author
There was a problem hiding this comment.
Thank you, all great suggestions! Changed.
mikelik
reviewed
Apr 20, 2023
mikelik
approved these changes
Apr 20, 2023
heifner
approved these changes
Apr 20, 2023
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.
This PR contains fix (and ut's) for the following issue (#579):
I expected to receive an action value is -90909090909090909. But the action return the value is -90909090909090910
[[eosio::action]] int64_t getvalue2() {
int64_t value = -90909090909090909;
eosio::print("getvalue2: ", value);
return value;
}
You can reproduce this issue through this repo https://github.com/quocle108/return-error