mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Make more things result-fail RawTable creation
This commit is contained in:
parent
87f6f17dd2
commit
65fe459835
1 changed files with 20 additions and 5 deletions
25
src/table.rs
25
src/table.rs
|
@ -755,19 +755,34 @@ impl<K, V> RawTable<K, V> {
|
||||||
align_of::<HashUint>(),
|
align_of::<HashUint>(),
|
||||||
pairs_size,
|
pairs_size,
|
||||||
align_of::<(K, V)>());
|
align_of::<(K, V)>());
|
||||||
assert!(!oflo, "capacity overflow");
|
|
||||||
|
if oflo {
|
||||||
|
// capacity overflow
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
// One check for overflow that covers calculation and rounding of size.
|
// One check for overflow that covers calculation and rounding of size.
|
||||||
let size_of_bucket = size_of::<HashUint>().checked_add(size_of::<(K, V)>()).unwrap();
|
let size_of_bucket = size_of::<HashUint>().checked_add(size_of::<(K, V)>()).unwrap();
|
||||||
assert!(size >=
|
|
||||||
capacity.checked_mul(size_of_bucket)
|
let cap_bytes = capacity.checked_mul(size_of_bucket);
|
||||||
.expect("capacity overflow"),
|
|
||||||
"capacity overflow");
|
if let Some(cap_bytes) = cap_bytes {
|
||||||
|
if size < cap_bytes {
|
||||||
|
// capacity overflow
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// capacity overflow
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FORK NOTE: Uses alloc shim instead of Heap.alloc
|
// FORK NOTE: Uses alloc shim instead of Heap.alloc
|
||||||
let buffer = alloc(size, alignment);
|
let buffer = alloc(size, alignment);
|
||||||
|
|
||||||
if buffer.is_null() {
|
if buffer.is_null() {
|
||||||
|
// OOM
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue