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

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jul 10 07:12:13 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 5e09c2986705a9c421d0471a27905e0e761e09e0
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=5e09c2986705a9c421d0471a27905e0e761e09e0

Author: qingdoa daoo <qingdao33122 at yahoo.com>
Date:   Sat Jul  8 14:58:07 2006 +0800

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 51c75e2..56322ba 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 5ea767f..dbaec34 100644
--- a/dlls/oleaut32/variant.c
+++ b/dlls/oleaut32/variant.c
@@ -718,15 +718,12 @@ HRESULT WINAPI VariantCopy(VARIANTARG* p
       }
       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)
       {




More information about the wine-cvs mailing list