From e47b3f0dfa3774964d48a1673bc6de2a90f5db44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Mon, 16 Jul 2007 15:32:13 +0000 Subject: [PATCH] Resize the string table when needed Fix a few warnings svn path=/trunk/; revision=27694 --- reactos/dll/win32/setupapi/devclass.c | 15 +++++++++++---- reactos/dll/win32/setupapi/setupapi_private.h | 8 ++++++++ reactos/dll/win32/setupapi/stringtable.c | 17 +++++++++++++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/reactos/dll/win32/setupapi/devclass.c b/reactos/dll/win32/setupapi/devclass.c index 9f2c5450ded..61215125c5f 100644 --- a/reactos/dll/win32/setupapi/devclass.c +++ b/reactos/dll/win32/setupapi/devclass.c @@ -558,9 +558,9 @@ SetupDiClassNameFromGuidExA( RequiredSize, MachineNameW, Reserved); if (ret) { - int len = WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName, + DWORD len = (DWORD)WideCharToMultiByte(CP_ACP, 0, ClassNameW, -1, ClassName, ClassNameSize, NULL, NULL); - if (len > ClassNameSize) + if (len == 0 || len > ClassNameSize) { SetLastError(ERROR_INSUFFICIENT_BUFFER); ret = FALSE; @@ -754,9 +754,9 @@ SetupDiGetClassDescriptionExA( ClassDescriptionSize * sizeof(WCHAR), RequiredSize, MachineNameW, Reserved); if (ret) { - int len = WideCharToMultiByte(CP_ACP, 0, ClassDescriptionW, -1, ClassDescription, + DWORD len = (DWORD)WideCharToMultiByte(CP_ACP, 0, ClassDescriptionW, -1, ClassDescription, ClassDescriptionSize, NULL, NULL); - if (len > ClassDescriptionSize) + if (len == 0 || len > ClassDescriptionSize) { SetLastError(ERROR_INSUFFICIENT_BUFFER); ret = FALSE; @@ -1185,7 +1185,14 @@ SetupDiGetClassDevsExW( FIXME(": flag DIGCF_PROFILE ignored\n"); if (Flags & DIGCF_DEVICEINTERFACE) + { + if (!ClassGuid) + { + SetLastError(ERROR_INVALID_PARAMETER); + goto cleanup; + } rc = SETUP_CreateInterfaceList(list, MachineName, ClassGuid, Enumerator, Flags & DIGCF_PRESENT); + } else { /* Determine which class(es) should be included in the deviceset */ diff --git a/reactos/dll/win32/setupapi/setupapi_private.h b/reactos/dll/win32/setupapi/setupapi_private.h index 276e6c46b6a..5e37cc93342 100644 --- a/reactos/dll/win32/setupapi/setupapi_private.h +++ b/reactos/dll/win32/setupapi/setupapi_private.h @@ -305,6 +305,14 @@ FreeFunctionPointer( DWORD WINAPI CaptureAndConvertAnsiArg(LPCSTR pSrc, LPWSTR *pDst); +VOID WINAPI MyFree(LPVOID lpMem); +LPVOID WINAPI MyMalloc(DWORD dwSize); +LPVOID WINAPI MyRealloc(LPVOID lpSrc, DWORD dwSize); +LPWSTR WINAPI DuplicateString(LPCWSTR lpSrc); +BOOL WINAPI IsUserAdmin(VOID); +LPWSTR WINAPI MultiByteToUnicode(LPCSTR lpMultiByteStr, UINT uCodePage); +LPSTR WINAPI UnicodeToMultiByte(LPCWSTR lpUnicodeStr, UINT uCodePage); + /* parser.c */ typedef BOOL (*FIND_CALLBACK)(LPCWSTR SectionName, PVOID Context); diff --git a/reactos/dll/win32/setupapi/stringtable.c b/reactos/dll/win32/setupapi/stringtable.c index 5785a5fd9b5..e8f621504c9 100644 --- a/reactos/dll/win32/setupapi/stringtable.c +++ b/reactos/dll/win32/setupapi/stringtable.c @@ -248,8 +248,21 @@ StringTableAddString(HSTRING_TABLE hStringTable, /* Check for filled slot table */ if (pStringTable->dwUsedSlots == pStringTable->dwMaxSlots) { - FIXME("Resize the string table!\n"); - return (DWORD)-1; + PTABLE_SLOT pNewSlots; + DWORD dwNewMaxSlots; + + /* FIXME: not thread safe */ + dwNewMaxSlots = pStringTable->dwMaxSlots * 2; + pNewSlots = MyMalloc(sizeof(TABLE_SLOT) * dwNewMaxSlots); + if (pNewSlots == NULL) + return (DWORD)-1; + memset(&pNewSlots[pStringTable->dwMaxSlots], 0, sizeof(TABLE_SLOT) * (dwNewMaxSlots - pStringTable->dwMaxSlots)); + memcpy(pNewSlots, pStringTable->pSlots, sizeof(TABLE_SLOT) * pStringTable->dwMaxSlots); + pNewSlots = InterlockedExchangePointer(&pStringTable->pSlots, pNewSlots); + MyFree(pNewSlots); + pStringTable->dwMaxSlots = dwNewMaxSlots; + + return StringTableAddString(hStringTable, lpString, dwFlags); } /* Search for an empty slot */