27 lines
1.1 KiB
Diff
27 lines
1.1 KiB
Diff
# UNDF: UNDF-2026-000000281
|
|
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).
|