From: Alex Henrie alexhenrie24@gmail.com
Discovered while investigating Bug 56551. --- dlls/setupapi/devinst.c | 4 ++-- dlls/setupapi/tests/devinst.c | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 7e2d683daa6..ea51e02086b 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -2135,7 +2135,7 @@ BOOL WINAPI SetupDiGetClassDescriptionExA( dwLength = ClassDescriptionSize; ret = !RegQueryValueExA( hKey, NULL, NULL, NULL, (LPBYTE)ClassDescription, &dwLength ); - if (RequiredSize) *RequiredSize = dwLength; + if (ret && RequiredSize) *RequiredSize = dwLength; RegCloseKey(hKey); return ret; } @@ -2169,7 +2169,7 @@ BOOL WINAPI SetupDiGetClassDescriptionExW( dwLength = ClassDescriptionSize * sizeof(WCHAR); ret = !RegQueryValueExW( hKey, NULL, NULL, NULL, (LPBYTE)ClassDescription, &dwLength ); - if (RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR); + if (ret && RequiredSize) *RequiredSize = dwLength / sizeof(WCHAR); RegCloseKey(hKey); return ret; } diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c index 2dc891d61f1..f568c7dd848 100644 --- a/dlls/setupapi/tests/devinst.c +++ b/dlls/setupapi/tests/devinst.c @@ -115,6 +115,7 @@ static void test_open_class_key(void) { static const char guidstr[] = "{6a55b5a4-3f65-11db-b704-0011955c2bdb}"; HKEY root_key, class_key; + DWORD size; LONG res;
SetLastError(0xdeadbeef); @@ -135,6 +136,11 @@ static void test_open_class_key(void) ok(class_key != INVALID_HANDLE_VALUE, "Failed to open class key, error %#lx.\n", GetLastError()); RegCloseKey(class_key);
+ size = 123; + res = SetupDiGetClassDescriptionA(&guid, NULL, 0, &size); + ok(!res, "Expected failure.\n"); + ok(size == 123, "Expected 123, got %ld.\n", size); + RegDeleteKeyA(root_key, guidstr); RegCloseKey(root_key); }