Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dynamic array not zeroing when growing #4599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed zeroing in resize_dynamic_array.
When a dynamic array has unused capacity and is resized to a size
greater than its capacity, the unused part of its capacity wasn't being
zeroed.
  • Loading branch information
Barinzaya committed Dec 19, 2024
commit 5f46b5ca50b48395edf08583278aa4bcd2c54ed9
8 changes: 5 additions & 3 deletions base/runtime/core_builtin.odin
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,12 @@ _resize_dynamic_array :: #force_inline proc(a: ^Raw_Dynamic_Array, size_of_elem,
return nil
}

if should_zero && a.len < length {
num_reused := min(a.cap, length) - a.len
intrinsics.mem_zero(([^]byte)(a.data)[a.len*size_of_elem:], num_reused*size_of_elem)
}

if length <= a.cap {
if should_zero && a.len < length {
intrinsics.mem_zero(([^]byte)(a.data)[a.len*size_of_elem:], (length-a.len)*size_of_elem)
}
a.len = max(length, 0)
return nil
}
Expand Down
Loading