advapi32: Sign-compare warnings fix (Try 2)

Andrew Talbot andrew.talbot at talbotville.com
Mon Jul 21 16:12:04 CDT 2008


I presume my first try was rejected because I failed to note that lstrlenW()
can handle a NULL pointer, whereas strlenW() cannot. Glad of
guidance if there are any other reasons.

Thanks,

-- Andy.
---
Changelog:
    advapi32: Sign-compare warnings fix.

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 089cf3e..55607c2 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -470,8 +470,8 @@ LSTATUS WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_
     KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
     DWORD total_size;
 
-    TRACE( "(%p,%d,%p,%p(%d),%p,%p,%p,%p)\n", hkey, index, name, name_len,
-           name_len ? *name_len : -1, reserved, class, class_len, ft );
+    TRACE( "(%p,%d,%p,%p(%u),%p,%p,%p,%p)\n", hkey, index, name, name_len,
+           name_len ? *name_len : 0, reserved, class, class_len, ft );
 
     if (reserved) return ERROR_INVALID_PARAMETER;
     if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
@@ -534,8 +534,8 @@ LSTATUS WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_l
     KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
     DWORD total_size;
 
-    TRACE( "(%p,%d,%p,%p(%d),%p,%p,%p,%p)\n", hkey, index, name, name_len,
-           name_len ? *name_len : -1, reserved, class, class_len, ft );
+    TRACE( "(%p,%d,%p,%p(%u),%p,%p,%p,%p)\n", hkey, index, name, name_len,
+           name_len ? *name_len : 0, reserved, class, class_len, ft );
 
     if (reserved) return ERROR_INVALID_PARAMETER;
     if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 3423cbe..07b846d 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -2119,28 +2119,31 @@ LookupAccountSidW(
     }
 
     if (dm) {
+        DWORD ac_len = ac ? strlenW(ac) : 0;
+        DWORD dm_len = strlenW(dm);
         BOOL status = TRUE;
-        if (*accountSize > lstrlenW(ac)) {
+
+        if (*accountSize > ac_len) {
             if (account)
                 lstrcpyW(account, ac);
         }
-        if (*domainSize > lstrlenW(dm)) {
+        if (*domainSize > dm_len) {
             if (domain)
                 lstrcpyW(domain, dm);
         }
-        if (((*accountSize != 0) && (*accountSize < strlenW(ac))) ||
-            ((*domainSize != 0) && (*domainSize < strlenW(dm)))) {
+        if (((*accountSize != 0) && (*accountSize < ac_len)) ||
+            ((*domainSize != 0) && (*domainSize < dm_len))) {
             SetLastError(ERROR_INSUFFICIENT_BUFFER);
             status = FALSE;
         }
         if (*domainSize)
-            *domainSize = strlenW(dm);
+            *domainSize = dm_len;
         else
-            *domainSize = strlenW(dm) + 1;
+            *domainSize = dm_len + 1;
         if (*accountSize)
-            *accountSize = strlenW(ac);
+            *accountSize = ac_len;
         else
-            *accountSize = strlenW(ac) + 1;
+            *accountSize = ac_len + 1;
         *name_use = use;
         HeapFree(GetProcessHeap(), 0, computer_name);
         return status;
@@ -4050,7 +4053,7 @@ static BOOL DumpSidNumeric(PSID psid, WCHAR **pwptr, ULONG *plen)
 
 static BOOL DumpSid(PSID psid, WCHAR **pwptr, ULONG *plen)
 {
-    int i;
+    size_t i;
     for (i = 0; i < sizeof(WellKnownSids) / sizeof(WellKnownSids[0]); i++)
     {
         if (WellKnownSids[i].wstr[0] && EqualSid(psid, (PSID)&(WellKnownSids[i].Sid.Revision)))
@@ -4102,7 +4105,7 @@ static void DumpRights(DWORD mask, WCHAR **pwptr, ULONG *plen)
 {
     static const WCHAR fmtW[] = {'0','x','%','x',0};
     WCHAR buf[15];
-    int i;
+    size_t i;
 
     if (mask == 0)
         return;
diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index c04eb8c..b4d5af0 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -1599,7 +1599,7 @@ QueryServiceConfigW( SC_HANDLE hService,
     move_string_to_buffer(&bufpos, &lpServiceConfig->lpServiceStartName);
     move_string_to_buffer(&bufpos, &lpServiceConfig->lpDisplayName);
 
-    if (bufpos - (LPBYTE)lpServiceConfig > cbBufSize)
+    if ((DWORD)(bufpos - (LPBYTE)lpServiceConfig) > cbBufSize)
         ERR("Buffer overflow!\n");
 
     TRACE("Image path           = %s\n", debugstr_w(lpServiceConfig->lpBinaryPathName) );



More information about the wine-patches mailing list