[ros-diffs] [hpoussin] 27694: Resize the string table when needed Fix a few warnings

hpoussin at svn.reactos.org hpoussin at svn.reactos.org
Mon Jul 16 17:32:14 CEST 2007


Author: hpoussin
Date: Mon Jul 16 19:32:13 2007
New Revision: 27694

URL: http://svn.reactos.org/svn/reactos?rev=27694&view=rev
Log:
Resize the string table when needed
Fix a few warnings

Modified:
    trunk/reactos/dll/win32/setupapi/devclass.c
    trunk/reactos/dll/win32/setupapi/setupapi_private.h
    trunk/reactos/dll/win32/setupapi/stringtable.c

Modified: trunk/reactos/dll/win32/setupapi/devclass.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/setupapi/devclass.c?rev=27694&r1=27693&r2=27694&view=diff
==============================================================================
--- trunk/reactos/dll/win32/setupapi/devclass.c (original)
+++ trunk/reactos/dll/win32/setupapi/devclass.c Mon Jul 16 19:32:13 2007
@@ -558,9 +558,9 @@
         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 @@
         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 @@
         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 */

Modified: trunk/reactos/dll/win32/setupapi/setupapi_private.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/setupapi/setupapi_private.h?rev=27694&r1=27693&r2=27694&view=diff
==============================================================================
--- trunk/reactos/dll/win32/setupapi/setupapi_private.h (original)
+++ trunk/reactos/dll/win32/setupapi/setupapi_private.h Mon Jul 16 19:32:13 2007
@@ -305,6 +305,14 @@
 
 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);

Modified: trunk/reactos/dll/win32/setupapi/stringtable.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/setupapi/stringtable.c?rev=27694&r1=27693&r2=27694&view=diff
==============================================================================
--- trunk/reactos/dll/win32/setupapi/stringtable.c (original)
+++ trunk/reactos/dll/win32/setupapi/stringtable.c Mon Jul 16 19:32:13 2007
@@ -248,8 +248,21 @@
     /* 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 */




More information about the Ros-diffs mailing list