58 lines
2 KiB
Diff
58 lines
2 KiB
Diff
# UNDF: UNDF-2026-000000280
|
||
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.
|