java-topology/defects/sfml/patch/sfml-0005-glcontext-extension-unordered-set.patch
russell@unturf.com 6bafc7f5e9 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
2026-03-27 11:57:12 -04:00

28 lines
995 B
Diff

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
}