mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 21:43:40 +00:00
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:
committed by
Ron Evans
parent
854f91ecf2
commit
b573ef3813
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user