Zero existing memory when using resize_soa (fixes #5614)

This commit is contained in:
Damian Tarnawski
2025-08-23 14:28:25 +02:00
parent 2b6ed996be
commit 18a2980d26
2 changed files with 58 additions and 0 deletions
+24
View File
@@ -178,9 +178,33 @@ resize_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int length: int, loc := #cal
if array == nil {
return nil
}
reserve_soa(array, length, loc) or_return
footer := raw_soa_footer(array)
old_len := footer.len
footer.len = length
if size_of(E) > 0 && length > old_len {
ti := type_info_of(typeid_of(T))
ti = type_info_base(ti)
si := &ti.variant.(Type_Info_Struct)
field_count := len(E) when intrinsics.type_is_array(E) else intrinsics.type_struct_field_count(E)
data := (^rawptr)(array)^
soa_offset := 0
for i in 0..<field_count {
type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
soa_offset = align_forward_int(soa_offset, align_of(E))
mem_zero(rawptr(uintptr(data) + uintptr(soa_offset) + uintptr(type.size * old_len)), type.size * (length - old_len))
soa_offset += type.size * cap(array)
}
}
return nil
}