Skip to content

Commit

Permalink
fix(transformer): NonEmptyStack::push write value before updating c…
Browse files Browse the repository at this point in the history
…ursor
  • Loading branch information
overlookmotel committed Sep 29, 2024
1 parent 1cee207 commit 0f89e74
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/helpers/stack/non_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ impl<T> NonEmptyStack<T> {
unsafe { self.push_slow(value) };
} else {
// Capacity for at least 1 more entry
self.cursor = new_cursor;
// SAFETY: We checked there is capacity for 1 more entry, so `self.cursor` is in bounds.
// `self.cursor` was aligned for `T`, and we added `size_of::<T>()` to pointer.
// `size_of::<T>()` is always a multiple of `T`'s alignment, so `self.cursor` must still be
// aligned for `T`.
unsafe { self.cursor.as_ptr().write(value) };
unsafe { new_cursor.as_ptr().write(value) };
self.cursor = new_cursor;
}
}

Expand Down

0 comments on commit 0f89e74

Please sign in to comment.