diff --git a/dlls/oleaut32/safearray.c b/dlls/oleaut32/safearray.c index 85afc4aa4ac..93d51869ead 100644 --- a/dlls/oleaut32/safearray.c +++ b/dlls/oleaut32/safearray.c @@ -383,7 +383,7 @@ static HRESULT SAFEARRAY_CopyData(SAFEARRAY *psa, SAFEARRAY *dest) { if (*lpBstr) { - *lpDest = SysAllocStringLen(*lpBstr, SysStringLen(*lpBstr)); + *lpDest = SysAllocStringByteLen((char*)*lpBstr, SysStringByteLen(*lpBstr)); if (!*lpDest) return E_OUTOFMEMORY; } @@ -887,7 +887,7 @@ HRESULT WINAPI SafeArrayPutElement(SAFEARRAY *psa, LONG *rgIndices, void *pvData if (lpBstr) { - *lpDest = SysAllocStringLen(lpBstr, SysStringLen(lpBstr)); + *lpDest = SysAllocStringByteLen((char*)lpBstr, SysStringByteLen(lpBstr)); if (!*lpDest) hRet = E_OUTOFMEMORY; } @@ -968,7 +968,7 @@ HRESULT WINAPI SafeArrayGetElement(SAFEARRAY *psa, LONG *rgIndices, void *pvData if (*lpBstr) { - *lpDest = SysAllocStringLen(*lpBstr, SysStringLen(*lpBstr)); + *lpDest = SysAllocStringByteLen((char*)*lpBstr, SysStringByteLen(*lpBstr)); if (!*lpBstr) hRet = E_OUTOFMEMORY; } diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c index 25bbee4d286..cdaf7ad3a89 100644 --- a/dlls/oleaut32/tests/vartype.c +++ b/dlls/oleaut32/tests/vartype.c @@ -4607,6 +4607,7 @@ static void test_SysAllocStringByteLen() const OLECHAR szTest[10] = { 'T','e','s','t','\0' }; const CHAR szTestA[6] = { 'T','e','s','t','\0','?' }; BSTR str; + HRESULT hres; str = SysAllocStringByteLen(szTestA, 0x80000000); ok (str == NULL, "Expected NULL, got %p\n", str); @@ -4640,9 +4641,20 @@ static void test_SysAllocStringByteLen() { const CHAR szTestTruncA[4] = { 'T','e','s','\0' }; LPINTERNAL_BSTR bstr = Get(str); + VARIANT vt1, vt2; ok (bstr->dwLen == 3, "Expected 3, got %ld\n", bstr->dwLen); ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n"); + + V_VT(&vt1) = VT_BSTR; + V_BSTR(&vt1) = str; + V_VT(&vt2) = VT_EMPTY; + hres = VariantCopy(&vt2, &vt1); + ok (hres == S_OK,"Failed to copy binary bstring with hres 0x%08lx\n", hres); + bstr = Get(V_BSTR(&vt2)); + ok (bstr->dwLen == 3, "Expected 3, got %ld\n", bstr->dwLen); + ok (!lstrcmpA((LPCSTR)bstr->szString, szTestTruncA), "String different\n"); + SysFreeString(str); } diff --git a/dlls/oleaut32/variant.c b/dlls/oleaut32/variant.c index ee2ce5e72df..df477b8ab23 100644 --- a/dlls/oleaut32/variant.c +++ b/dlls/oleaut32/variant.c @@ -727,7 +727,7 @@ HRESULT WINAPI VariantCopy(VARIANTARG* pvargDest, VARIANTARG* pvargSrc) { if (V_BSTR(pvargSrc)) { - V_BSTR(pvargDest) = SysAllocStringLen(V_BSTR(pvargSrc), SysStringLen(V_BSTR(pvargSrc))); + V_BSTR(pvargDest) = SysAllocStringByteLen((char*)V_BSTR(pvargSrc), SysStringByteLen(V_BSTR(pvargSrc))); if (!V_BSTR(pvargDest)) hres = E_OUTOFMEMORY; } @@ -852,7 +852,7 @@ HRESULT WINAPI VariantCopyInd(VARIANT* pvargDest, VARIANTARG* pvargSrc) else if (V_VT(pSrc) == (VT_BSTR|VT_BYREF)) { /* Native doesn't check that *V_BSTRREF(pSrc) is valid */ - V_BSTR(pvargDest) = SysAllocStringLen(*V_BSTRREF(pSrc), SysStringLen(*V_BSTRREF(pSrc))); + V_BSTR(pvargDest) = SysAllocStringByteLen((char*)*V_BSTRREF(pSrc), SysStringByteLen(*V_BSTRREF(pSrc))); } else if (V_VT(pSrc) == (VT_RECORD|VT_BYREF)) {