diff options
author | 12101111 <w12101111@gmail.com> | 2021-10-09 00:01:04 +0800 |
---|---|---|
committer | 12101111 <w12101111@gmail.com> | 2021-10-09 00:01:04 +0800 |
commit | 0115eb8dd887649ab605f8bad559372df21b5ad1 (patch) | |
tree | 646596fe976bdef71cf03c924dd91ddf5d57242e | |
parent | 6ae238e868751116bdeedd0c2b4cc9a0c054189e (diff) | |
download | servo-0115eb8dd887649ab605f8bad559372df21b5ad1.tar.gz servo-0115eb8dd887649ab605f8bad559372df21b5ad1.zip |
Fix UB in hashglobe
-rw-r--r-- | components/hashglobe/src/table.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/components/hashglobe/src/table.rs b/components/hashglobe/src/table.rs index 0fe08f2b052..e418c11b04d 100644 --- a/components/hashglobe/src/table.rs +++ b/components/hashglobe/src/table.rs @@ -836,7 +836,9 @@ impl<K, V> RawTable<K, V> { pub fn new(capacity: usize) -> Result<RawTable<K, V>, FailedAllocationError> { unsafe { let ret = RawTable::try_new_uninitialized(capacity)?; - ptr::write_bytes(ret.hashes.ptr(), 0, capacity); + if capacity > 0 { + ptr::write_bytes(ret.hashes.ptr(), 0, capacity); + } Ok(ret) } } |