From 0115eb8dd887649ab605f8bad559372df21b5ad1 Mon Sep 17 00:00:00 2001 From: 12101111 Date: Sat, 9 Oct 2021 00:01:04 +0800 Subject: [PATCH] Fix UB in hashglobe --- components/hashglobe/src/table.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 RawTable { pub fn new(capacity: usize) -> Result, 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) } }