diff --git a/crates/environ/src/collections/entity_set.rs b/crates/environ/src/collections/entity_set.rs index 5eac9c24383f..d4bc95647c0e 100644 --- a/crates/environ/src/collections/entity_set.rs +++ b/crates/environ/src/collections/entity_set.rs @@ -67,7 +67,7 @@ where /// Returns `true` if `k` was not present in the set, i.e. this is a /// newly-added element. Returns `false` otherwise. pub fn insert(&mut self, k: K) -> Result { - self.inner.try_ensure_capacity(k.index())?; + self.inner.try_ensure_capacity(k.index() + 1)?; Ok(self.inner.insert(k)) } diff --git a/crates/fuzzing/tests/oom.rs b/crates/fuzzing/tests/oom.rs index 2e022e5aefd8..3e55ca6cc511 100644 --- a/crates/fuzzing/tests/oom.rs +++ b/crates/fuzzing/tests/oom.rs @@ -124,6 +124,24 @@ fn secondary_map_try_insert() -> Result<()> { }) } +#[test] +fn entity_set_ensure_capacity() -> Result<()> { + OomTest::new().test(|| { + let mut set = EntitySet::::new(); + set.ensure_capacity(100)?; + Ok(()) + }) +} + +#[test] +fn entity_set_insert() -> Result<()> { + OomTest::new().test(|| { + let mut set = EntitySet::::new(); + set.insert(Key::from_u32(256))?; + Ok(()) + }) +} + #[test] fn vec_with_capacity() -> Result<()> { OomTest::new().test(|| {