Fix overflow bugs in DictionaryHashMap that only surfaced without small RAM

This commit is contained in:
vlofgren 2022-07-16 18:58:19 +02:00
parent 661577b456
commit c71cc3d43a
2 changed files with 8 additions and 4 deletions

View File

@ -59,12 +59,14 @@ public class DictionaryData {
private final LongBuffer keys;
private int size;
private final int capacity;
public DictionaryDataBank(int start_idx, int sz) {
this.start_idx = start_idx;
this.capacity = sz;
keys = ByteBuffer.allocateDirect(8*sz).asLongBuffer();
keys = ByteBuffer.allocateDirect(8*capacity).asLongBuffer();
size = 0;
}
@ -92,6 +94,9 @@ public class DictionaryData {
}
public int add(long newKey) {
if (size >= capacity)
return -1;
keys.put(size, newKey);
return start_idx + size++;

View File

@ -66,8 +66,7 @@ public class DictionaryHashMap {
logger.debug("Buffer size sanity checked passed");
}
dictionaryData = new DictionaryData(Math.min(1<<30, Math.max(32, (int)(sizeMemory/4))));
dictionaryData = new DictionaryData((int)Math.min(1<<27, Math.max(32L, sizeMemory/4)));
initializeBuffers();
}