aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author12101111 <w12101111@gmail.com>2021-10-09 00:01:04 +0800
committer12101111 <w12101111@gmail.com>2021-10-09 00:01:04 +0800
commit0115eb8dd887649ab605f8bad559372df21b5ad1 (patch)
tree646596fe976bdef71cf03c924dd91ddf5d57242e
parent6ae238e868751116bdeedd0c2b4cc9a0c054189e (diff)
downloadservo-0115eb8dd887649ab605f8bad559372df21b5ad1.tar.gz
servo-0115eb8dd887649ab605f8bad559372df21b5ad1.zip
Fix UB in hashglobe
-rw-r--r--components/hashglobe/src/table.rs4
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)
}
}