Copy BSTRs byte wise.

Added a testcase for byte wise copy of VT_BSTR variant with
VariantCopy().
This commit is contained in:
Marcus Meissner 2004-01-09 00:58:01 +00:00 committed by Alexandre Julliard
parent e24d3fec2d
commit 2ac287e875
3 changed files with 17 additions and 5 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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))
{