fix: Handle capacity overflow
This commit is contained in:
parent
6c9ad14e90
commit
0f88c943bf
|
@ -135,6 +135,7 @@ impl Buffer {
|
||||||
let new_layout = Layout::from_size_align_unchecked(cap, 1);
|
let new_layout = Layout::from_size_align_unchecked(cap, 1);
|
||||||
self.data = alloc(new_layout);
|
self.data = alloc(new_layout);
|
||||||
} else {
|
} else {
|
||||||
|
assert!(cap <= std::usize::MAX / 2, "capacity is too large");
|
||||||
let old_layout = Layout::from_size_align_unchecked(self.capacity, 1);
|
let old_layout = Layout::from_size_align_unchecked(self.capacity, 1);
|
||||||
self.data = realloc(self.data, old_layout, cap);
|
self.data = realloc(self.data, old_layout, cap);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue