mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Avoid accessing unallocated bytes in list.incref
This commit is contained in:
parent
9b6798ead1
commit
44cd1ee9c4
2 changed files with 11 additions and 4 deletions
|
@ -143,10 +143,12 @@ pub const RocList = extern struct {
|
|||
pub fn incref(self: RocList, amount: isize, elements_refcounted: bool) void {
|
||||
// If the list is unique and not a seamless slice, the length needs to be store on the heap if the elements are refcounted.
|
||||
if (elements_refcounted and self.isUnique() and !self.isSeamlessSlice()) {
|
||||
// - 1 is refcount.
|
||||
// - 2 is size on heap.
|
||||
const ptr = @as([*]usize, @alignCast(@ptrCast(self.getAllocationPtr()))) - 2;
|
||||
ptr[0] = self.length;
|
||||
if (self.getAllocationPtr()) |source| {
|
||||
// - 1 is refcount.
|
||||
// - 2 is size on heap.
|
||||
const ptr = @as([*]usize, @alignCast(@ptrCast(source))) - 2;
|
||||
ptr[0] = self.length;
|
||||
}
|
||||
}
|
||||
utils.increfDataPtrC(self.getAllocationPtr(), amount);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue