SFML 5 defects: VideoMode dedup x3 (139x), allWindows erase (1001x), GL ext (149x) AngelScript 3 defects: FindNewOwner (100x), CompileSwitch (250x) Three.js 5 defects: WebGL binding (22x), StackNode filter (1875x), NodeBuilder (517x) pygame 4 defects: remove_internal (3001x), spritecollide dokill (3001x), switch_layer (3001x) Whitepaper: 98→115 sites, 44→48 ecosystems All unit tests pass: 6/6 each
26 lines
1.1 KiB
Diff
26 lines
1.1 KiB
Diff
Fixes sfml-0004: WindowImplX11 destructor uses std::find() on allWindows vector.
|
|
|
|
--- a/src/SFML/Window/Unix/WindowImplX11.cpp
|
|
+++ b/src/SFML/Window/Unix/WindowImplX11.cpp
|
|
@@ -63,7 +63,8 @@
|
|
namespace
|
|
{
|
|
- std::vector<sf::priv::WindowImplX11*> allWindows;
|
|
+ std::set<sf::priv::WindowImplX11*> allWindows; // FIX sfml-0004: O(1) insert/erase — CWE-407
|
|
sf::Mutex allWindowsMutex;
|
|
+ // Note: std::vector removed; iteration in allWindows loop at line 1153 uses range-for
|
|
}
|
|
|
|
@@ -777,7 +777,7 @@ WindowImplX11::~WindowImplX11()
|
|
Lock lock(allWindowsMutex);
|
|
- allWindows.erase(std::find(allWindows.begin(), allWindows.end(), this));
|
|
- // was: O(n) find then O(n) erase — CWE-407; closing N windows = O(n²)
|
|
+ allWindows.erase(this); // O(log n)
|
|
|
|
@@ -1598,7 +1598,7 @@ void WindowImplX11::initialize()
|
|
Lock lock(allWindowsMutex);
|
|
- allWindows.push_back(this);
|
|
+ allWindows.insert(this); // O(log n)
|
|
|
|
# The iteration at line 1153 (for itr : allWindows) works unchanged with std::set.
|
|
# No ordering guarantees were relied upon with the vector (LIFO ordering not used).
|