sfml/angelscript/threejs/pygame: unit tests + patches + whitepaper (115 sites, 48 ecosystems)

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
This commit is contained in:
russell@unturf.com 2026-03-27 11:57:12 -04:00
parent 442a6156e3
commit 6bafc7f5e9
17 changed files with 1189 additions and 18 deletions

View file

@ -0,0 +1,57 @@
Fixes sfml-0001/0002/0003: VideoMode deduplication on Unix, Win32, OSX
All three platforms use identical pattern: std::find() on growing vector inside a loop.
--- a/src/SFML/Window/Unix/VideoModeImpl.cpp
+++ b/src/SFML/Window/Unix/VideoModeImpl.cpp
@@ -40,6 +40,7 @@
#include <algorithm>
#include <vector>
+#include <set>
// ... (in getFullscreenModes)
- std::vector<VideoMode> modes;
+ std::vector<VideoMode> modes;
+ std::set<VideoMode> modeSet; // FIX sfml-0001: O(1) dedup — CWE-407
// ... nested loop over depths × sizes:
- if (std::find(modes.begin(), modes.end(), mode) == modes.end())
- modes.push_back(mode);
+ // was: O(n) linear scan per (depth,size) pair — CWE-407
+ if (modeSet.insert(mode).second) // O(log n) — insert returns {iter, inserted}
+ modes.push_back(mode);
--- a/src/SFML/Window/Win32/VideoModeImpl.cpp
+++ b/src/SFML/Window/Win32/VideoModeImpl.cpp
@@ -37,6 +37,7 @@
#include <algorithm>
+#include <set>
- std::vector<VideoMode> modes;
+ std::vector<VideoMode> modes;
+ std::set<VideoMode> modeSet; // FIX sfml-0002: CWE-407
// in EnumDisplaySettings loop:
- if (std::find(modes.begin(), modes.end(), mode) == modes.end())
- modes.push_back(mode);
+ if (modeSet.insert(mode).second)
+ modes.push_back(mode);
--- a/src/SFML/Window/OSX/VideoModeImpl.cpp
+++ b/src/SFML/Window/OSX/VideoModeImpl.cpp
@@ -39,6 +39,7 @@
#include <algorithm>
+#include <set>
- std::vector<VideoMode> modes;
+ std::vector<VideoMode> modes;
+ std::set<VideoMode> modeSet; // FIX sfml-0003: CWE-407
// in CFArray loop:
- if (std::find(modes.begin(), modes.end(), mode) == modes.end())
- modes.push_back(mode);
+ if (modeSet.insert(mode).second)
+ modes.push_back(mode);
# Note: VideoMode already has operator< defined (required for std::set) — no other changes needed.
# modeSet is local to getFullscreenModes(), modes vector is still returned as-is.

View file

@ -0,0 +1,26 @@
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).

View file

@ -0,0 +1,28 @@
Fixes sfml-0005: GlContext::isExtensionAvailable() uses std::find() on string vector.
--- a/src/SFML/Window/GlContext.cpp
+++ b/src/SFML/Window/GlContext.cpp
@@ -210,7 +210,8 @@
namespace
{
- std::vector<std::string> extensions;
+ std::unordered_set<std::string> extensions; // FIX sfml-0005: O(1) lookup — CWE-407
+ // was: std::vector<std::string>, O(n) scan per isExtensionAvailable() call (~200-500 extensions)
}
@@ -263,13 +263,13 @@
extensions.clear();
// ... population unchanged, just push_back → insert:
- extensions.push_back(std::string(extension, extensionString));
+ extensions.insert(std::string(extension, extensionString));
- extensions.push_back(extensionString);
+ extensions.insert(extensionString);
@@ -473,5 +473,5 @@
bool GlContext::isExtensionAvailable(const char* name)
{
- return std::find(extensions.begin(), extensions.end(), name) != extensions.end();
+ return extensions.count(name) > 0; // O(1) hash lookup
}