fix: Handle capacity overflow

This commit is contained in:
Kogia-sima 2020-06-18 00:49:59 +09:00
parent 6c9ad14e90
commit 0f88c943bf
1 changed files with 1 additions and 0 deletions

View File

@ -135,6 +135,7 @@ impl Buffer {
let new_layout = Layout::from_size_align_unchecked(cap, 1);
self.data = alloc(new_layout);
} else {
assert!(cap <= std::usize::MAX / 2, "capacity is too large");
let old_layout = Layout::from_size_align_unchecked(self.capacity, 1);
self.data = realloc(self.data, old_layout, cap);
}