Resize the string table when needed

Fix a few warnings

svn path=/trunk/; revision=27694
This commit is contained in:
Hervé Poussineau
2007-07-16 15:32:13 +00:00
parent 029287899f
commit e47b3f0dfa
3 changed files with 34 additions and 6 deletions
+11 -4
View File
@@ -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 */
@@ -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);
+15 -2
View File
@@ -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 */