Skip to content
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

Infinite loop due to integer overflow #26

Closed
codahale opened this issue Nov 12, 2014 · 2 comments
Closed

Infinite loop due to integer overflow #26

codahale opened this issue Nov 12, 2014 · 2 comments

Comments

@codahale
Copy link

The following code never returns:

new Histogram(20000000, 100000000, 5);

It hangs here:

at org.HdrHistogram.AbstractHistogram.getBucketsNeededToCoverValue(AbstractHistogram.java:1440)
at org.HdrHistogram.AbstractHistogram.init(AbstractHistogram.java:189)
at org.HdrHistogram.AbstractHistogram.<init>(AbstractHistogram.java:152)
at org.HdrHistogram.Histogram.<init>(Histogram.java:139)

At line 1440, it sets trackableValue to (subBucketCount - 1) << unitMagnitude which is (262144 - 1) << 24, which overflows to -16777216. As a result the loop condition never returns true, because trackableValue eventually shifts down to 0.

@giltene
Copy link
Member

giltene commented Nov 12, 2014

The bug is in int / long conversion (shift left ops done on int instead of long before assignment).

Fixed with change dc4f9eb

Added test case with change 9c1b0b1

The test case also demonstrates the percentile roll-over point due to rounding (3 total values in histogram 83.33% will round down to 2nd value, 83.34% will round up to 3rd value).

@giltene giltene closed this as completed Nov 12, 2014
@mikeb01
Copy link
Contributor

mikeb01 commented Nov 12, 2014

Was broken in the C port too. Fix also applied in 9abf30a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants