Skip to content
Merged
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
7 changes: 4 additions & 3 deletions crates/oxc_allocator/src/string_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,10 @@ impl<'a> StringBuilder<'a> {
// `DEFAULT_MIN_CAPACITY` in `with_capacity_in` and `from_str_in`, then can remove this line.
let additional = cmp::max(current_capacity, DEFAULT_MIN_CAPACITY);

let new_capacity = current_capacity
.checked_add(additional)
.expect("attempt to grow `StringBuilder` beyond `isize::MAX` bytes");
// `current_capacity` is max `isize::MAX` bytes.
// `additional` is also max `isize::MAX` bytes.
// Therefore this addition cannot overflow.
let new_capacity = current_capacity + additional;

// SAFETY: We already allocated this, so must have a valid layout
let old_layout = unsafe { Layout::from_size_align_unchecked(current_capacity, 1) };
Expand Down
Loading