Signed-off-by: Nikolay Sivov nsivov@codeweavers.com ---
v2: now with a test
dlls/mshtml/htmllocation.c | 7 +++++-- dlls/mshtml/tests/htmllocation.c | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/dlls/mshtml/htmllocation.c b/dlls/mshtml/htmllocation.c index de66ff5670..59b20f614d 100644 --- a/dlls/mshtml/htmllocation.c +++ b/dlls/mshtml/htmllocation.c @@ -351,13 +351,16 @@ static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p) if(url.nPort) { /* <hostname>:<port> */ const WCHAR format[] = {'%','u',0}; - DWORD len = url.dwHostNameLength + 1 + 5; + DWORD len, port_len; + WCHAR portW[6]; WCHAR *buf;
+ port_len = snprintfW(portW, sizeof(portW)/sizeof(portW[0]), format, url.nPort); + len = url.dwHostNameLength + 1 /* ':' */ + port_len; buf = *p = SysAllocStringLen(NULL, len); memcpy(buf, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR)); buf[url.dwHostNameLength] = ':'; - snprintfW(buf + url.dwHostNameLength + 1, 6, format, url.nPort); + memcpy(buf + url.dwHostNameLength + 1, portW, port_len * sizeof(WCHAR)); }else *p = SysAllocStringLen(url.lpszHostName, url.dwHostNameLength);
diff --git a/dlls/mshtml/tests/htmllocation.c b/dlls/mshtml/tests/htmllocation.c index ee241e79af..458960a8d3 100644 --- a/dlls/mshtml/tests/htmllocation.c +++ b/dlls/mshtml/tests/htmllocation.c @@ -168,10 +168,15 @@ static void test_host(IHTMLLocation *loc, const struct location_test *test)
hres = IHTMLLocation_get_host(loc, &str); ok(hres == S_OK, "%s: get_host failed: 0x%08x\n", test->name, hres); - if(hres == S_OK) + if(hres == S_OK){ + int len = test->host ? strlen(test->host) : 0; ok(str_eq_wa(str, test->host), "%s: expected retrieved host to be L"%s", was: %s\n", test->name, test->host, wine_dbgstr_w(str)); + ok(SysStringLen(str) == len, "%s: unexpected string length %u, expected %u\n", + test->name, SysStringLen(str), len); + } + SysFreeString(str); }