java-topology/defects/fbneo-0001/patch/fbneo-0001.patch

70 lines
2.3 KiB
Diff

# UNDF: UNDF-2026-000001045
# UNDF: UNDF-2026-XXXXXXXXX
--- a/src/burn/burn.cpp
+++ b/src/burn/burn.cpp
@@ -1,6 +1,7 @@
// Burn - Drivers module
#include "version.h"
+#include <unordered_map>
#include "burnint.h"
#include "timer.h"
//#include "burn_sound.h" // included in burnint.h
@@ -88,6 +89,9 @@ static char** pszShortName = NULL, ** pszFullNameA = NULL;
static wchar_t** pszFullNameW = NULL;
static char szBackupNameW[MAX_PATH * sizeof(wchar_t)];
+// Hash index from short name to driver array index for O(1) BurnDrvGetIndex.
+static std::unordered_map<std::string, INT32> g_drvIndexMap;
+
static INT32 BurnCheckMMXSupport()
{
#if defined (_X86_) && defined (_MSC_VER)
@@ -108,6 +112,8 @@ static void BurnGameListInit()
if (0 == nBurnDrvCount) return;
pszShortName = (char** )malloc(nBurnDrvCount * sizeof(char*));
+ g_drvIndexMap.clear();
+ g_drvIndexMap.reserve(nBurnDrvCount);
pszFullNameA = (char** )malloc(nBurnDrvCount * sizeof(char*));
pszFullNameW = (wchar_t**)malloc(nBurnDrvCount * sizeof(wchar_t*));
@@ -122,6 +128,7 @@ static void BurnGameListInit()
if (NULL != pszShortName[i]) {
strcpy(pszShortName[i], pDriver[i]->szShortName);
pDriver[i]->szShortName = pszShortName[i];
+ g_drvIndexMap[pDriver[i]->szShortName] = (INT32)i;
}
if (NULL != pszFullNameA[i]) {
strcpy(pszFullNameA[i], pDriver[i]->szFullNameA);
@@ -149,6 +156,7 @@ static void BurnGameListExit()
if ((NULL != pszFullNameW) && (NULL != pszFullNameW[i])) free(pszFullNameW[i]);
}
+ g_drvIndexMap.clear();
if (NULL != pszShortName) free(pszShortName);
if (NULL != pszFullNameA) free(pszFullNameA);
if (NULL != pszFullNameW) free(pszFullNameW);
@@ -584,12 +592,13 @@ extern "C" wchar_t* BurnDrvGetFullNameW(UINT32 i)
return pDriver[i]->szFullNameW;
}
-extern "C" INT32 BurnDrvGetIndex(char* szName)
+// BurnDrvGetIndex -- O(1) hash lookup, was O(N) linear scan over all drivers.
+extern "C" INT32 BurnDrvGetIndex(char* szName) // CWE-407 fix: unordered_map
{
if (NULL == szName) return -1;
- for (UINT32 i = 0; i < nBurnDrvCount; i++) {
- if (0 == strcmp(szName, pDriver[i]->szShortName)) {
-// nBurnDrvActive = i;
- return i;
- }
- }
-
- return -1;
+ auto it = g_drvIndexMap.find(szName);
+ if (it != g_drvIndexMap.end())
+ return it->second;
+ return -1;
}