oleaut32: Copying a NULL BSTR should result in an empty BSTR in VariantCopy.

This commit is contained in:
qingdoa daoo 2006-07-08 14:58:07 +08:00 committed by Alexandre Julliard
parent 4598c973b2
commit 5e09c29867
2 changed files with 23 additions and 9 deletions

View File

@ -528,6 +528,23 @@ static void test_VariantCopy(void)
vt | ExtraFlags[i], V_VT(&vDst));
}
}
/* Test that copying a NULL BSTR results in an empty BSTR */
memset(&vDst, 0, sizeof(vDst));
V_VT(&vDst) = VT_EMPTY;
memset(&vSrc, 0, sizeof(vSrc));
V_VT(&vSrc) = VT_BSTR;
hres = VariantCopy(&vDst, &vSrc);
ok(hres == S_OK, "Copy(NULL BSTR): Failed to copy a NULL BSTR\n");
if (hres == S_OK)
{
ok((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst),
"Copy(NULL BSTR): should have non-NULL result\n");
if ((V_VT(&vDst) == VT_BSTR) && V_BSTR(&vDst))
{
ok(*V_BSTR(&vDst) == 0, "Copy(NULL BSTR): result not empty\n");
}
}
}
/* Determine if a vt is valid for VariantCopyInd() */

View File

@ -718,15 +718,12 @@ HRESULT WINAPI VariantCopy(VARIANTARG* pvargDest, VARIANTARG* pvargSrc)
}
else if (V_VT(pvargSrc) == VT_BSTR)
{
if (V_BSTR(pvargSrc))
{
V_BSTR(pvargDest) = SysAllocStringByteLen((char*)V_BSTR(pvargSrc), SysStringByteLen(V_BSTR(pvargSrc)));
if (!V_BSTR(pvargDest))
{
TRACE("!V_BSTR(pvargDest), SysAllocStringByteLen() failed to allocate %d bytes\n", SysStringByteLen(V_BSTR(pvargSrc)));
hres = E_OUTOFMEMORY;
}
}
V_BSTR(pvargDest) = SysAllocStringByteLen((char*)V_BSTR(pvargSrc), SysStringByteLen(V_BSTR(pvargSrc)));
if (!V_BSTR(pvargDest))
{
TRACE("!V_BSTR(pvargDest), SysAllocStringByteLen() failed to allocate %d bytes\n", SysStringByteLen(V_BSTR(pvargSrc)));
hres = E_OUTOFMEMORY;
}
}
else if (V_VT(pvargSrc) == VT_RECORD)
{