Fix UB in hashglobe

This commit is contained in:
12101111 2021-10-09 00:01:04 +08:00
parent 6ae238e868
commit 0115eb8dd8
No known key found for this signature in database
GPG key ID: 97785FADF38A97DC

View file

@ -836,7 +836,9 @@ impl<K, V> RawTable<K, V> {
pub fn new(capacity: usize) -> Result<RawTable<K, V>, FailedAllocationError> { pub fn new(capacity: usize) -> Result<RawTable<K, V>, FailedAllocationError> {
unsafe { unsafe {
let ret = RawTable::try_new_uninitialized(capacity)?; 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) Ok(ret)
} }
} }