[Openvpn-devel,v2] tapctl: Fix sign conversion warnings

Message ID 20261201203811.4743-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] tapctl: Fix sign conversion warnings |

Commit Message

Gert Doering Dec. 1, 2026, 8:38 p.m. UTC
  From: Frank Lichtenheld <frank@lichtenheld.com>

- Mostly related to the annoying LSTATUS return
  value of Reg* functions.
- Fixes one actual bug where get_reg_string could
  return ERROR_SUCCESS when ExpandEnvironmentStrings
  failed. But not sure how to trigger that.

Change-Id: I473c876cecffb4d057f6ffb23e50c3274de95989
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2381
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2381
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
  

Patch

diff --git a/src/tapctl/tap.c b/src/tapctl/tap.c
index 672bd2d..5aac7ff 100644
--- a/src/tapctl/tap.c
+++ b/src/tapctl/tap.c
@@ -102,11 +102,6 @@ 
 }
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 /**
  * Returns length of string of strings
  *
@@ -121,7 +116,7 @@ 
     for (s = szz; s[0]; s += wcslen(s) + 1)
     {
     }
-    return s - szz;
+    return (size_t)(s - szz);
 }
 
 
@@ -391,7 +386,7 @@ 
     }
 
     DWORD dwValueType = REG_NONE, dwSize = 0;
-    DWORD dwResult = RegQueryValueEx(hKey, szName, NULL, &dwValueType, NULL, &dwSize);
+    DWORD dwResult = (DWORD)RegQueryValueEx(hKey, szName, NULL, &dwValueType, NULL, &dwSize);
     if (dwResult != ERROR_SUCCESS)
     {
         /* MSDN does not mention RegQueryValueEx() to set GetLastError(). But
@@ -415,7 +410,7 @@ 
                 return ERROR_OUTOFMEMORY;
             }
 
-            dwResult = RegQueryValueEx(hKey, szName, NULL, NULL, (LPBYTE)szValue, &dwSize);
+            dwResult = (DWORD)RegQueryValueEx(hKey, szName, NULL, NULL, (LPBYTE)szValue, &dwSize);
             if (dwResult != ERROR_SUCCESS)
             {
                 SetLastError(dwResult);
@@ -441,6 +436,7 @@ 
                 DWORD dwCountExpResult = ExpandEnvironmentStrings(szValue, szValueExp, dwCountExp);
                 if (dwCountExpResult == 0)
                 {
+                    dwResult = GetLastError();
                     msg(M_NONFATAL | M_ERRNO, "%s: expanding \"%ls\" registry value failed",
                         __FUNCTION__, szName);
                     free(szValueExp);
@@ -533,7 +529,7 @@ 
         /* Query the NetCfgInstanceId value. Using get_reg_string() right on might clutter the
          * output with error messages while the registry is still being populated. */
         LPWSTR szCfgGuidString = NULL;
-        dwResult = RegQueryValueEx(hKey, L"NetCfgInstanceId", NULL, NULL, NULL, NULL);
+        dwResult = (DWORD)RegQueryValueEx(hKey, L"NetCfgInstanceId", NULL, NULL, NULL, NULL);
         if (dwResult != ERROR_SUCCESS)
         {
             if (dwResult == ERROR_FILE_NOT_FOUND && --iNumAttempts > 0)
@@ -953,7 +949,7 @@ 
 
     /* Open network adapter registry key. */
     HKEY hKey = NULL;
-    dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hKey);
+    dwResult = (DWORD)RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_QUERY_VALUE, &hKey);
     if (dwResult != ERROR_SUCCESS)
     {
         SetLastError(dwResult);
@@ -1120,7 +1116,7 @@ 
 
         /* Open network adapter registry key. */
         HKEY hKey = NULL;
-        dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_READ, &hKey);
+        dwResult = (DWORD)RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_READ, &hKey);
         if (dwResult != ERROR_SUCCESS)
         {
             SetLastError(dwResult);
@@ -1185,10 +1181,6 @@ 
     return dwResult;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 tap_free_adapter_list(_In_ struct tap_adapter_node *pAdapterList)
 {