Skip to content
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
5 changes: 5 additions & 0 deletions buffer/buffer.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ fn Buffer::grow_if_necessary(self : Buffer, required : Int) -> Unit {
if space >= required {
break space
}
// Guard against integer overflow: when space > Int max / 2 (1073741823),
// doubling would exceed 32-bit Int range. Fall back to exact allocation.
if space > 1073741823 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might use a constant instead of a random number. Also the current runtime should be put into account -> moonbitlang/moonbit-docs#1155

break required
}
continue space * 2
}
if enough_space != self.data.length() {
Expand Down
Loading