Skip to content

Commit b6c5f49

Browse files
committed
GPU (Windows): more strict check
1 parent 5b6416e commit b6c5f49

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/detection/gpu/gpu_windows.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
const char* ffDetectGPUImpl(FFlist* gpus, FF_MAYBE_UNUSED const FFinstance* instance)
88
{
9-
DISPLAY_DEVICEW displayDevice = {.cb = sizeof(displayDevice) };
9+
DISPLAY_DEVICEW displayDevice = { .cb = sizeof(displayDevice) };
1010
wchar_t regKey[MAX_PATH] = L"SYSTEM\\CurrentControlSet\\Control\\Video\\{";
11-
const uint32_t regKeyPrefixLength = strlen("SYSTEM\\CurrentControlSet\\Control\\Video\\{");
12-
const uint32_t deviceKeyPrefixLength = strlen("\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Video\\{");
11+
const uint32_t regKeyPrefixLength = (uint32_t) wcslen(regKey);
12+
const uint32_t deviceKeyPrefixLength = strlen("\\Registry\\Machine\\") + regKeyPrefixLength;
1313

1414
for (DWORD i = 0; EnumDisplayDevicesW(NULL, i, &displayDevice, 0); ++i)
1515
{
1616
if (displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) continue;
1717

1818
const uint32_t deviceKeyLength = (uint32_t) wcslen(displayDevice.DeviceKey);
19-
if (wmemcmp(&displayDevice.DeviceKey[deviceKeyLength - 4], L"0000", 4) != 0) continue;
19+
if (deviceKeyLength != 100 || wmemcmp(&displayDevice.DeviceKey[deviceKeyLength - 4], L"0000", 4) != 0) continue;
2020

2121
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
2222
ffStrbufInit(&gpu->vendor);
@@ -27,7 +27,7 @@ const char* ffDetectGPUImpl(FFlist* gpus, FF_MAYBE_UNUSED const FFinstance* inst
2727
gpu->type = FF_GPU_TYPE_UNKNOWN;
2828
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
2929

30-
if (deviceKeyLength == 100 && displayDevice.DeviceKey[deviceKeyPrefixLength - 1] == '{')
30+
if (displayDevice.DeviceKey[deviceKeyPrefixLength - 1] == '{')
3131
{
3232
wmemcpy(regKey + regKeyPrefixLength, displayDevice.DeviceKey + deviceKeyPrefixLength, 100 - regKeyPrefixLength + 1);
3333
FF_HKEY_AUTO_DESTROY hKey = NULL;

0 commit comments

Comments
 (0)