fix(gc): correct old size calculation in block realloc.

Using blocksPerStateByte instead of bytesPerBlock caused the old size to be underestimated for multi-block allocations, leading to data truncation on growing reallocations.
This commit is contained in:
Konstantin Sharlaimov
2026-07-13 20:57:04 +02:00
committed by Ron Evans
parent 854f91ecf2
commit b573ef3813
+1 -1
View File
@@ -510,7 +510,7 @@ func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer {
lastBlock := firstBlock.findHead()
// Calculate the size of the original allocation body.
oldSize := uintptr(lastBlock-firstBlock)*blocksPerStateByte + (bytesPerBlock - unsafe.Sizeof(objHeader{}))
oldSize := uintptr(lastBlock-firstBlock)*bytesPerBlock + (bytesPerBlock - unsafe.Sizeof(objHeader{}))
if size <= oldSize {
// The requested size is less than the old size.