diff options
author | Yahan Zhou <yahan@google.com> | 2024-03-06 20:53:25 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-03-06 20:53:25 +0000 |
commit | 5b466f8d01b2d1d91885e1be2e2c621cce4d358e (patch) | |
tree | d2614232e1771745d8911c0d27e3a64f8af63c96 | |
parent | 119c7cdf37eae6f5ce49ac4f94e1a7bca9f107d3 (diff) | |
parent | c96f2874d39eed86c33283edfc65e348cac61ac0 (diff) | |
download | aemu-emu-34-2-dev.tar.gz |
Merge "Abort when trying to insert duplicated entry" into mainemu-34-2-dev
-rw-r--r-- | base/HybridEntityManager_unittest.cpp | 2 | ||||
-rw-r--r-- | base/include/aemu/base/containers/HybridEntityManager.h | 14 |
2 files changed, 13 insertions, 3 deletions
diff --git a/base/HybridEntityManager_unittest.cpp b/base/HybridEntityManager_unittest.cpp index afc5670..cc67dc7 100644 --- a/base/HybridEntityManager_unittest.cpp +++ b/base/HybridEntityManager_unittest.cpp @@ -24,7 +24,7 @@ using TestHCM = HybridEntityManager<kTestMaxIndex, uint64_t, int>; TEST(HybridEntityManager, UpdateIndex) { TestHCM m; // Occupy all linear entries. - for (uint32_t i = 0; i < kTestMaxIndex + 1; i++) { + for (uint32_t i = 0; i < kTestMaxIndex; i++) { m.add(i, 1); } int indices[4]; diff --git a/base/include/aemu/base/containers/HybridEntityManager.h b/base/include/aemu/base/containers/HybridEntityManager.h index 68452d9..c5a0c5a 100644 --- a/base/include/aemu/base/containers/HybridEntityManager.h +++ b/base/include/aemu/base/containers/HybridEntityManager.h @@ -57,7 +57,12 @@ public: mIndexForMap = maxIndex; } nextIndex = mIndexForMap; - mMap[nextIndex] = data; + auto emplaced = mMap.emplace(nextIndex, data); + if (!emplaced.second) { + fprintf(stderr, "%s: fatal: trying to insert duplicated entry 0x%llx\n", __func__, + (unsigned long long)nextIndex); + abort(); + } ++mIndexForMap; return EM::makeHandle(nextIndex, 1, type); } @@ -71,7 +76,12 @@ public: AutoLock lock(mMapLock); // Fixed allocations require us to update mIndexForMap to catch up with it. mIndexForMap = std::max(index_u64 + 1, mIndexForMap); - mMap[index_u64] = data; + auto emplaced = mMap.emplace(index_u64, data); + if (!emplaced.second) { + fprintf(stderr, "%s: fatal: trying to insert duplicated entry 0x%llx\n", __func__, + (unsigned long long)index_u64); + abort(); + } return index; } } |