Huw Davies : iphlpapi: Use proper multibyte to unicode conversion.
Alexandre Julliard
julliard at winehq.org
Mon Sep 16 16:57:23 CDT 2013
Module: wine
Branch: master
Commit: 57ed5bf32e4b8bb6e539f9df1e57f2f1b2827cb7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=57ed5bf32e4b8bb6e539f9df1e57f2f1b2827cb7
Author: Huw Davies <huw at codeweavers.com>
Date: Mon Sep 16 13:50:38 2013 +0100
iphlpapi: Use proper multibyte to unicode conversion.
---
dlls/iphlpapi/iphlpapi_main.c | 24 +++++++-----------------
1 files changed, 7 insertions(+), 17 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 5f795ec..789c339 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -1027,13 +1027,11 @@ static BOOL is_ip_address_string(const char *str)
static ULONG get_dns_suffix(WCHAR *suffix, ULONG *len)
{
ULONG size, i;
- char *found_suffix = NULL;
+ const char *found_suffix = "";
+ /* Always return a NULL-terminated string, even if it's empty. */
initialise_resolver();
- /* Always return a NULL-terminated string, even if it's empty. */
- size = sizeof(WCHAR);
- for (i = 0, found_suffix = NULL;
- !found_suffix && i < MAXDNSRCH + 1 && _res.dnsrch[i]; i++)
+ for (i = 0; !*found_suffix && i < MAXDNSRCH + 1 && _res.dnsrch[i]; i++)
{
/* This uses a heuristic to select a DNS suffix:
* the first, non-IP address string is selected.
@@ -1041,22 +1039,14 @@ static ULONG get_dns_suffix(WCHAR *suffix, ULONG *len)
if (!is_ip_address_string(_res.dnsrch[i]))
found_suffix = _res.dnsrch[i];
}
- if (found_suffix)
- size += strlen(found_suffix) * sizeof(WCHAR);
+
+ size = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, NULL, 0 ) * sizeof(WCHAR);
if (!suffix || *len < size)
{
*len = size;
return ERROR_BUFFER_OVERFLOW;
}
- *len = size;
- if (found_suffix)
- {
- char *p;
-
- for (p = found_suffix; *p; p++)
- *suffix++ = *p;
- }
- *suffix = 0;
+ *len = MultiByteToWideChar( CP_UNIXCP, 0, found_suffix, -1, suffix, *len / sizeof(WCHAR) ) * sizeof(WCHAR);
return ERROR_SUCCESS;
}
@@ -1139,7 +1129,7 @@ ULONG WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG family, ULONG flags, P
if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && aa->OperStatus == IfOperStatusUp)
aa->DnsSuffix = dnsSuffix;
else
- aa->DnsSuffix = (WCHAR *)((BYTE*)dnsSuffix + dns_suffix_size - 2);
+ aa->DnsSuffix = dnsSuffix + dns_suffix_size / sizeof(WCHAR) - 1;
}
ret = ERROR_SUCCESS;
}
More information about the wine-cvs
mailing list