From 5e09c2986705a9c421d0471a27905e0e761e09e0 Mon Sep 17 00:00:00 2001 From: qingdoa daoo Date: Sat, 8 Jul 2006 14:58:07 +0800 Subject: [PATCH] oleaut32: Copying a NULL BSTR should result in an empty BSTR in VariantCopy. --- dlls/oleaut32/tests/vartest.c | 17 +++++++++++++++++ dlls/oleaut32/variant.c | 15 ++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/dlls/oleaut32/tests/vartest.c b/dlls/oleaut32/tests/vartest.c index 51c75e233c..56322badb8 100644 --- a/dlls/oleaut32/tests/vartest.c +++ b/dlls/oleaut32/tests/vartest.c @@ -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() */ diff --git a/dlls/oleaut32/variant.c b/dlls/oleaut32/variant.c index 5ea767fa4f..dbaec34d9b 100644 --- a/dlls/oleaut32/variant.c +++ b/dlls/oleaut32/variant.c @@ -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) {