Skip to content

Commit b573ef3

Browse files
digitalentitydeadprogram
authored andcommitted
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.
1 parent 854f91e commit b573ef3

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/runtime/gc_blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer {
510510
lastBlock := firstBlock.findHead()
511511

512512
// Calculate the size of the original allocation body.
513-
oldSize := uintptr(lastBlock-firstBlock)*blocksPerStateByte + (bytesPerBlock - unsafe.Sizeof(objHeader{}))
513+
oldSize := uintptr(lastBlock-firstBlock)*bytesPerBlock + (bytesPerBlock - unsafe.Sizeof(objHeader{}))
514514

515515
if size <= oldSize {
516516
// The requested size is less than the old size.

0 commit comments

Comments
 (0)