mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-02 19:32:17 +00:00
fix slice refcounting mistakes that can modify data before a list
This commit is contained in:
parent
2002868b56
commit
2772aa4912
1 changed files with 2 additions and 2 deletions
|
@ -132,7 +132,7 @@ pub const RocList = extern struct {
|
|||
// This needs to be called when creating seamless slices from unique list.
|
||||
// It will put the allocation size on the heap to enable the seamless slice to free the underlying allocation.
|
||||
fn setAllocationElementCount(self: RocList, elements_refcounted: bool) void {
|
||||
if (elements_refcounted) {
|
||||
if (elements_refcounted and !self.isSeamlessSlice()) {
|
||||
// - 1 is refcount.
|
||||
// - 2 is size on heap.
|
||||
const ptr = @as([*]usize, @alignCast(@ptrCast(self.getAllocationDataPtr()))) - 2;
|
||||
|
@ -185,7 +185,7 @@ pub const RocList = extern struct {
|
|||
return utils.REFCOUNT_ONE;
|
||||
}
|
||||
|
||||
const ptr: [*]usize = @as([*]usize, @ptrCast(@alignCast(self.bytes)));
|
||||
const ptr: [*]usize = @as([*]usize, @ptrCast(@alignCast(self.getAllocationDataPtr())));
|
||||
return (ptr - 1)[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue