java-topology/defects/cocos2d-0002/patch/cocos2d-0002.patch
russell@unturf.com 1b98cac200 cocos2d-x: 3 CWE-407 defects, MOAD 0002-0005 CLEAN
cocos2d-0001: EventDispatcher _toRemovedListeners std::find O(L*R) MEDIUM 2.4x
cocos2d-0002: PhysicsWorld collisionBeginCallback std::find O(J_body*J_world) MEDIUM 11.6x
cocos2d-0003: BoneNode::visit _boneSkins.contains O(C*S) per frame MEDIUM 7.3x

MOAD-0002 (Intertangle): heavy singleton pattern (Director, etc.) but architectural, not patchable
MOAD-0003 (Leaked Context): no thread_local usage, CLEAN
MOAD-0004 (Logged Secret): no credential logging, CLEAN
MOAD-0005 (Thundering Herd): TextureCache uses unordered_map, CLEAN

6/6 unit tests PASS.
2026-03-31 12:10:19 -04:00

36 lines
1.2 KiB
Diff

# UNDF: UNDF-2026-000000961
--- a/cocos/physics/CCPhysicsWorld.h
+++ b/cocos/physics/CCPhysicsWorld.h
@@ -33,6 +33,7 @@
#include <list>
#include <vector>
+#include <unordered_set>
struct cpSpace;
@@ -230,6 +231,7 @@
std::vector<PhysicsJoint*> _joints;
+ std::unordered_set<PhysicsJoint*> _jointsSet; // O(1) membership mirror of _joints
std::vector<PhysicsJoint*> _delayAddJoints;
--- a/cocos/physics/CCPhysicsWorld.cpp
+++ b/cocos/physics/CCPhysicsWorld.cpp
@@ -310,7 +310,7 @@ bool PhysicsWorld::collisionBeginCallback(PhysicsContact& contact)
// check the joint is collision enable or not
for (PhysicsJoint* joint : jointsA)
{
- if (std::find(_joints.begin(), _joints.end(), joint) == _joints.end())
+ if (_jointsSet.find(joint) == _jointsSet.end())
{
continue;
}
@@ -688,6 +688,7 @@ void PhysicsWorld::updateJoints()
if (joint->initJoint())
{
_joints.push_back(joint);
+ _jointsSet.insert(joint);
}
else
{
// Also update doRemoveJoint to maintain _jointsSet:
// When removing from _joints, also call _jointsSet.erase(joint).