java-topology/defects/0ad-0003/patch/0ad-0003.patch
russell@unturf.com 223ccb3fee 0ad: 4 defects, 5-MOAD scan across pathfinding/visibility/templates/lobby
0ad-0001 CCmpObstructionManager dirty shapes vector+std::find O(N*D) HIGH 4.1x
0ad-0002 CCmpRangeManager m_ModifiedEntities vector+std::find O(E*M) HIGH 25.8x
0ad-0003 CCmpTemplateManager FindUsedTemplates vector+std::find O(T^2) MEDIUM 5.9x
0ad-0004 XmppClient+NetServer lobby auth token logged verbatim CWE-312 MEDIUM

MOAD-0002 (Intertangle): g_ globals are deliberate single-thread game arch, CLEAN
MOAD-0003 (Leaked Context): thread_local properly scoped, CLEAN
MOAD-0005 (Thundering Herd): single-threaded sim, no cache stampede, CLEAN

4/4 unit tests PASS, UNDF 956-959
2026-03-31 11:58:37 -04:00

21 lines
933 B
Diff

# UNDF: UNDF-2026-000000958
--- a/source/simulation2/components/CCmpTemplateManager.cpp
+++ b/source/simulation2/components/CCmpTemplateManager.cpp
@@ -1,5 +1,6 @@
// CWE-407: CCmpTemplateManager::FindUsedTemplates uses std::find on a growing
// std::vector for dedup, O(T^2) where T = number of entity-template pairs.
// With T=2000 entities this is 2M comparisons. Fix: use std::unordered_set.
+#include <unordered_set>
@@ -237,10 +238,10 @@
std::vector<std::string> CCmpTemplateManager::FindUsedTemplates() const
{
- std::vector<std::string> usedTemplates;
+ std::unordered_set<std::string> seen;
for (const std::pair<const entity_id_t, std::string>& p : m_LatestTemplates)
- if (std::find(usedTemplates.begin(), usedTemplates.end(), p.second) == usedTemplates.end())
- usedTemplates.push_back(p.second);
- return usedTemplates;
+ seen.insert(p.second);
+ return std::vector<std::string>(seen.begin(), seen.end());
}