Skip to content

Commit

Permalink
Merge pull request #9 from cehteh/main
Browse files Browse the repository at this point in the history
FIX: push() update length after new element got written
  • Loading branch information
vadixidav authored Sep 17, 2024
2 parents 73b53a2 + b0fcd56 commit 6f6cc86
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ impl<H, T> HeaderVec<H, T> {
pub fn push(&mut self, item: T) -> Option<*const ()> {
let old_len = self.len();
let new_len = old_len + 1;
self.header_mut().len = new_len;
let old_capacity = self.capacity();
// If it isn't big enough.
let previous_pointer = if new_len > old_capacity {
Expand All @@ -209,6 +208,7 @@ impl<H, T> HeaderVec<H, T> {
unsafe {
core::ptr::write(self.start_ptr_mut().add(old_len), item);
}
self.header_mut().len = new_len;
previous_pointer
}

Expand Down

0 comments on commit 6f6cc86

Please sign in to comment.