Fix Invalid slotkey access when a slot is exhausted
All checks were successful
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m19s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m19s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 5m46s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 5m38s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m54s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m58s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m57s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m57s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m51s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m30s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m35s
Bigfoot / Clang Format Checks (push) Successful in 12s
All checks were successful
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m19s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m19s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 5m46s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 5m38s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m54s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m58s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m57s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m57s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m51s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m30s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m35s
Bigfoot / Clang Format Checks (push) Successful in 12s
This commit is contained in:
@@ -98,7 +98,7 @@ class SlotMap
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
SlotKey Insert(ARGS&&... p_args)
|
SlotKey Insert(ARGS&&... p_args)
|
||||||
{
|
{
|
||||||
ASSERT(UtilsAssertHandler, m_data.size() < SlotKey::MAX_INDEX, "Too many elements for SlotMap!");
|
ASSERT(UtilsAssertHandler, m_slots.size() < SlotKey::MAX_INDEX, "All slots have been exhausted!");
|
||||||
|
|
||||||
const typename SlotKey::IndexType dataIndex = static_cast<SlotKey::IndexType>(m_data.size());
|
const typename SlotKey::IndexType dataIndex = static_cast<SlotKey::IndexType>(m_data.size());
|
||||||
m_data.emplace_back(std::forward<ARGS>(p_args)...);
|
m_data.emplace_back(std::forward<ARGS>(p_args)...);
|
||||||
@@ -145,7 +145,8 @@ class SlotMap
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool Has(const SlotKey p_slotKey) const
|
bool Has(const SlotKey p_slotKey) const
|
||||||
{
|
{
|
||||||
return p_slotKey.Index() < m_slots.size() && p_slotKey.Version() == m_slots[p_slotKey.Index()].Version();
|
return p_slotKey.Valid() &&
|
||||||
|
(p_slotKey.Index() < m_slots.size() && p_slotKey.Version() == m_slots[p_slotKey.Index()].Version());
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@@ -192,7 +193,7 @@ class SlotMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
eastl::vector<TYPE>::size_type Empty() const
|
bool Empty() const
|
||||||
{
|
{
|
||||||
return m_data.empty();
|
return m_data.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,33 @@ TEST_F(SlotMapFixture, Remove_ShouldNotRecycleASlotWhenVersionWasExhausted)
|
|||||||
// Dead slot must not be recycled; a new insert must allocate a fresh slot index
|
// Dead slot must not be recycled; a new insert must allocate a fresh slot index
|
||||||
const auto newKey = m_slotMap.Insert(2);
|
const auto newKey = m_slotMap.Insert(2);
|
||||||
EXPECT_NE(newKey.Index(), key.Index());
|
EXPECT_NE(newKey.Index(), key.Index());
|
||||||
|
|
||||||
|
// Ensure an invalid key does not return an exhausted slot
|
||||||
|
EXPECT_EQ(m_slotMap.Get(SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {}), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(SlotMapFixture, Remove_ShouldNotDoAnythingInCaseOfDoubleRemove)
|
||||||
|
{
|
||||||
|
const auto slotKey1 = m_slotMap.Insert(42);
|
||||||
|
const auto slotKey2 = m_slotMap.Insert(69);
|
||||||
|
|
||||||
|
m_slotMap.Remove(slotKey1);
|
||||||
|
m_slotMap.Remove(slotKey1);
|
||||||
|
|
||||||
|
EXPECT_EQ(*m_slotMap.Get(slotKey2), 69);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(SlotMapFixture, Remove_ShouldNotDoAnythingInCaseStaleKey)
|
||||||
|
{
|
||||||
|
const auto slotKey1 = m_slotMap.Insert(42);
|
||||||
|
|
||||||
|
m_slotMap.Remove(SlotMap<std::uint32_t, SlotMapVersion, SlotMapIndex>::SlotKey {2, 0});
|
||||||
|
|
||||||
|
EXPECT_EQ(*m_slotMap.Get(slotKey1), 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************/
|
/****************************************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user