mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Prevent arithmetic operations from overflowing, Fix #244
This commit is contained in:
@@ -449,7 +449,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
private void initOffsetsAndBulks() {
|
||||
segmentHeadersOffset = segmentHeadersOffset();
|
||||
|
||||
long segmentHeadersSize = actualSegments * segmentHeaderSize;
|
||||
final long segmentHeadersSize = (long) actualSegments * (long) segmentHeaderSize;
|
||||
segmentsOffset = segmentHeadersOffset + segmentHeadersSize;
|
||||
|
||||
if (createdOrInMemory) {
|
||||
|
||||
@@ -570,7 +570,7 @@ public abstract class SegmentStages implements SegmentLock, LocksInterface {
|
||||
public abstract boolean segmentTierInit();
|
||||
|
||||
public void initSegmentTier() {
|
||||
tierIndex = segmentIndex + 1; // tiers are 1-counted
|
||||
tierIndex = segmentIndex + 1L; // tiers are 1-counted
|
||||
tierBaseAddr = hh.h().segmentBaseAddr(segmentIndex);
|
||||
// assign the field of stage on which init() checks last, because flushed in segmentIndex()
|
||||
// initialization
|
||||
|
||||
@@ -66,12 +66,12 @@ public class PoissonDistribution {
|
||||
double k = Math.sqrt((1.0 - p) / p);
|
||||
double tmp = mu - k * sigma;
|
||||
if (tmp > lower) {
|
||||
lower = ((int) Math.ceil(tmp)) - 1;
|
||||
lower = ((int) Math.ceil(tmp)) - 1L;
|
||||
}
|
||||
k = 1.0 / k;
|
||||
tmp = mu + k * sigma;
|
||||
if (tmp < upper) {
|
||||
upper = ((int) Math.ceil(tmp)) - 1;
|
||||
upper = ((int) Math.ceil(tmp)) - 1L;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -910,7 +910,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
TierCountersArea.segmentIndex(tierCountersAreaAddr));
|
||||
final int tier = TierCountersArea.tier(tierCountersAreaAddr);
|
||||
final long tierIndex = actualSegments +
|
||||
(bulkIndex << log2TiersInBulk) + tierIndexOffsetWithinBulk + 1;
|
||||
((long) bulkIndex << log2TiersInBulk) + tierIndexOffsetWithinBulk + 1;
|
||||
context.initSegmentTier(tier, tierIndex, tierBaseAddr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user