- Notifications
You must be signed in to change notification settings - Fork 525
fix of overflow detection for numeric primitive types #121
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
Conversation
Codecov Report
@@ Coverage Diff @@ ## master #121 +/- ## ========================================== - Coverage 68.53% 68.38% -0.15% ========================================== Files 107 107 Lines 7084 7101 +17 Branches 1347 1376 +29 ========================================== + Hits 4855 4856 +1 - Misses 1800 1806 +6 - Partials 429 439 +10
Continue to review full report at Codecov.
|
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.
there might be better ways to do less calculation
if (value == Long.MIN_VALUE) { | ||
throw iter.reportError("readLongSlowPath", "value is too large for long"); | ||
if (value < multmin) { | ||
throw iter.reportError("readIntSlowPath", "value is too large for int"); |
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.
throw iter.reportError("readIntSlowPath", "value is too large for int");
should be long
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.
fixed by following 2 commits
please sqash them in case of merge
value = (value << 3) + (value << 1) + ind; | ||
if (value < 0 && value != Long.MIN_VALUE) { | ||
value = (value << 3) + (value << 1); | ||
if (value < limit + ind) { |
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.
may be we can change
if (value < limit + ind) { throw iter.reportError("readLongSlowPath", "value is too large for long"); } value -= ind;
to
value -= ind; if (value >= 0) { throw iter.reportError("readLongSlowPath", "value is too large for long"); }
if value is positive, we add additional value != Long.MIN_VALUE
check
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.
limit + ind
is required to properly detect overflow when number to parse is Long.MAX_VALUE + 1 to do not raise overflow when parsing Long.MIN_VALUE
} | ||
| ||
static long readLongSlowPath(JsonIterator iter, long value) throws IOException { | ||
static long readLongSlowPath(final JsonIterator iter, long value, final boolean negative) throws IOException { |
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.
final boolean negative
is not necessary. we can always return negative number, and make it positive from the readLong. this way saved one branch.
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.
some additional param is required until we inline these slow path methods or split them on pair of methods (one for negative, other for positive)
Problem is that 40000000000000000000 (too big to be mapped to java.langLong number in JSON) is succesfully parsed to 3106511852580896768L using current implementation from develop.