Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2381?usp=email
to review the following change.
Change subject: tapctl: Fix sign conversion warnings
......................................................................
tapctl: Fix sign conversion warnings
- 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 <[email protected]>
---
M src/tapctl/tap.c
1 file changed, 28 insertions(+), 37 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/81/2381/1
diff --git a/src/tapctl/tap.c b/src/tapctl/tap.c
index 76ec569..ab0bfbb 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);
}
@@ -382,7 +377,7 @@
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise
*/
-static DWORD
+static LSTATUS
get_reg_string(_In_ HKEY hKey, _In_ LPCWSTR szName, _Out_ LPWSTR *pszValue)
{
if (pszValue == NULL)
@@ -391,15 +386,15 @@
}
DWORD dwValueType = REG_NONE, dwSize = 0;
- DWORD dwResult = RegQueryValueEx(hKey, szName, NULL, &dwValueType, NULL,
&dwSize);
- if (dwResult != ERROR_SUCCESS)
+ LSTATUS lResult = RegQueryValueEx(hKey, szName, NULL, &dwValueType, NULL,
&dwSize);
+ if (lResult != ERROR_SUCCESS)
{
/* MSDN does not mention RegQueryValueEx() to set GetLastError(). But
we do have an error code. Set last error manually. */
- SetLastError(dwResult);
+ SetLastError((DWORD)lResult);
msg(M_NONFATAL | M_ERRNO, "%s: enumerating \"%ls\" registry value
failed", __FUNCTION__,
szName);
- return dwResult;
+ return lResult;
}
switch (dwValueType)
@@ -415,14 +410,14 @@
return ERROR_OUTOFMEMORY;
}
- dwResult = RegQueryValueEx(hKey, szName, NULL, NULL,
(LPBYTE)szValue, &dwSize);
- if (dwResult != ERROR_SUCCESS)
+ lResult = RegQueryValueEx(hKey, szName, NULL, NULL,
(LPBYTE)szValue, &dwSize);
+ if (lResult != ERROR_SUCCESS)
{
- SetLastError(dwResult);
+ SetLastError((DWORD)lResult);
msg(M_NONFATAL | M_ERRNO, "%s: reading \"%ls\" registry value
failed", __FUNCTION__,
szName);
free(szValue);
- return dwResult;
+ return lResult;
}
if (dwValueType == REG_EXPAND_SZ)
@@ -441,11 +436,12 @@
DWORD dwCountExpResult = ExpandEnvironmentStrings(szValue,
szValueExp, dwCountExp);
if (dwCountExpResult == 0)
{
+ DWORD dwError = GetLastError();
msg(M_NONFATAL | M_ERRNO, "%s: expanding \"%ls\" registry
value failed",
__FUNCTION__, szName);
free(szValueExp);
free(szValue);
- return dwResult;
+ return (LSTATUS)dwError;
}
else if (dwCountExpResult <= dwCountExp)
{
@@ -511,8 +507,6 @@
get_net_adapter_guid(_In_ HDEVINFO hDeviceInfoSet, _In_ PSP_DEVINFO_DATA
pDeviceInfoData,
_In_ int iNumAttempts, _Out_ LPGUID pguidAdapter)
{
- DWORD dwResult = ERROR_BAD_ARGUMENTS;
-
if (pguidAdapter == NULL || iNumAttempts < 1)
{
return ERROR_BAD_ARGUMENTS;
@@ -523,48 +517,49 @@
DIREG_DRV, KEY_READ);
if (hKey == INVALID_HANDLE_VALUE)
{
- dwResult = GetLastError();
+ DWORD dwResult = GetLastError();
msg(M_NONFATAL | M_ERRNO, "%s: SetupDiOpenDevRegKey failed",
__FUNCTION__);
return dwResult;
}
+ LSTATUS lResult = ERROR_BAD_ARGUMENTS;
while (iNumAttempts > 0)
{
/* 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);
- if (dwResult != ERROR_SUCCESS)
+ lResult = RegQueryValueEx(hKey, L"NetCfgInstanceId", NULL, NULL, NULL,
NULL);
+ if (lResult != ERROR_SUCCESS)
{
- if (dwResult == ERROR_FILE_NOT_FOUND && --iNumAttempts > 0)
+ if (lResult == ERROR_FILE_NOT_FOUND && --iNumAttempts > 0)
{
/* Wait and retry. */
Sleep(1000);
continue;
}
- SetLastError(dwResult);
+ SetLastError((DWORD)lResult);
msg(M_NONFATAL | M_ERRNO, "%s: querying \"NetCfgInstanceId\"
registry value failed",
__FUNCTION__);
break;
}
/* Read the NetCfgInstanceId value now. */
- dwResult = get_reg_string(hKey, L"NetCfgInstanceId", &szCfgGuidString);
- if (dwResult != ERROR_SUCCESS)
+ lResult = get_reg_string(hKey, L"NetCfgInstanceId", &szCfgGuidString);
+ if (lResult != ERROR_SUCCESS)
{
break;
}
- dwResult = SUCCEEDED(CLSIDFromString(szCfgGuidString,
(LPCLSID)pguidAdapter))
- ? ERROR_SUCCESS
- : ERROR_INVALID_DATA;
+ lResult = SUCCEEDED(CLSIDFromString(szCfgGuidString,
(LPCLSID)pguidAdapter))
+ ? ERROR_SUCCESS
+ : ERROR_INVALID_DATA;
free(szCfgGuidString);
break;
}
RegCloseKey(hKey);
- return dwResult;
+ return (DWORD)lResult;
}
@@ -982,7 +977,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);
@@ -991,7 +986,7 @@
}
LPWSTR szOldName = NULL;
- dwResult = get_reg_string(hKey, L"Name", &szOldName);
+ dwResult = (DWORD)get_reg_string(hKey, L"Name", &szOldName);
if (dwResult != ERROR_SUCCESS)
{
SetLastError(dwResult);
@@ -1149,7 +1144,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);
@@ -1159,7 +1154,7 @@
/* Read adapter name. */
LPWSTR szName = NULL;
- dwResult = get_reg_string(hKey, L"Name", &szName);
+ dwResult = (DWORD)get_reg_string(hKey, L"Name", &szName);
if (dwResult != ERROR_SUCCESS)
{
SetLastError(dwResult);
@@ -1214,10 +1209,6 @@
return dwResult;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
void
tap_free_adapter_list(_In_ struct tap_adapter_node *pAdapterList)
{
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2381?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I473c876cecffb4d057f6ffb23e50c3274de95989
Gerrit-Change-Number: 2381
Gerrit-PatchSet: 1
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel