Skip to content

Commit e33556d

Browse files
Adjust rowslot address if realloc relocates the memory
1 parent 363f731 commit e33556d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

jni/CursorWindow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <assert.h>
2525
#include <string.h>
2626
#include <stdlib.h>
27+
#include <stdint.h>
2728

2829
#include <jni.h>
2930
// #include <JNIHelp.h>
@@ -103,6 +104,9 @@ field_slot_t * CursorWindow::allocRow()
103104
return NULL;
104105
}
105106

107+
// Record the original offset of the rowSlot prior to allocation of the field directory
108+
uint32_t rowSlotOffset = (uint8_t*)rowSlot - mData;
109+
106110
// Allocate the slots for the field directory
107111
size_t fieldDirSize = mHeader->numColumns * sizeof(field_slot_t);
108112
uint32_t fieldDirOffset = alloc(fieldDirSize);
@@ -114,6 +118,10 @@ field_slot_t * CursorWindow::allocRow()
114118
field_slot_t * fieldDir = (field_slot_t *)offsetToPtr(fieldDirOffset);
115119
memset(fieldDir, 0x0, fieldDirSize);
116120

121+
// Reset the rowSlot pointer relative to mData
122+
// If the last alloc relocated mData this will be rowSlot's new address, otherwise the value will not change
123+
rowSlot = (row_slot_t*)(mData + rowSlotOffset);
124+
117125
LOG_WINDOW("Allocated row %u, rowSlot is at offset %u, fieldDir is %d bytes at offset %u\n", (mHeader->numRows - 1), ((uint8_t *)rowSlot) - mData, fieldDirSize, fieldDirOffset);
118126
rowSlot->offset = fieldDirOffset;
119127

0 commit comments

Comments
 (0)