Robert Shearman : OLE: Fix SafeArrayCopy for NULL pvData.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Dec 12 06:44:31 CST 2005


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

Author: Robert Shearman <rob at codeweavers.com>
Date:   Mon Dec 12 11:52:51 2005 +0100

OLE: Fix SafeArrayCopy for NULL pvData.
It is allowed to copy a SAFEARRAY with a NULL pvData, as long as
cbElements is non-zero. Add a test for this and fix the safe array
code.

---

 dlls/oleaut32/safearray.c       |   10 +++++++++-
 dlls/oleaut32/tests/safearray.c |   15 ++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/dlls/oleaut32/safearray.c b/dlls/oleaut32/safearray.c
index b84226b..4ff056a 100644
--- a/dlls/oleaut32/safearray.c
+++ b/dlls/oleaut32/safearray.c
@@ -355,7 +355,9 @@ static HRESULT SAFEARRAY_DestroyData(SAF
 /* Copy data items from one array to another */
 static HRESULT SAFEARRAY_CopyData(SAFEARRAY *psa, SAFEARRAY *dest)
 {
-  if (!psa->pvData || !dest->pvData || psa->fFeatures & FADF_DATADELETED)
+  if (!psa->pvData)
+    return S_OK;
+  else if (!dest->pvData || psa->fFeatures & FADF_DATADELETED)
     return E_INVALIDARG;
   else
   {
@@ -1378,6 +1380,12 @@ HRESULT WINAPI SafeArrayCopy(SAFEARRAY *
   if (!psa)
     return S_OK; /* Handles copying of NULL arrays */
 
+  if (!psa->cbElements)
+  {
+    ERR("not copying an array of 0 elements\n");
+    return E_INVALIDARG;
+  }
+
   if (psa->fFeatures & (FADF_RECORD|FADF_HAVEIID|FADF_HAVEVARTYPE))
   {
     VARTYPE vt;
diff --git a/dlls/oleaut32/tests/safearray.c b/dlls/oleaut32/tests/safearray.c
index a39d43a..d7909e7 100644
--- a/dlls/oleaut32/tests/safearray.c
+++ b/dlls/oleaut32/tests/safearray.c
@@ -1418,7 +1418,7 @@ static void test_SafeArrayClear(void)
 static void test_SafeArrayCopy(void)
 {
   SAFEARRAYBOUND sab;
-  SAFEARRAY *sa;
+  SAFEARRAY *sa, *sa2;
   VARIANTARG vSrc, vDst;
   HRESULT hres;
 
@@ -1450,6 +1450,19 @@ static void test_SafeArrayCopy(void)
 
   SafeArrayDestroy(V_ARRAY(&vSrc));
   SafeArrayDestroy(V_ARRAY(&vDst));
+
+  hres = SafeArrayAllocDescriptor(1, &sa);
+  ok(hres == S_OK, "SafeArrayAllocDescriptor failed with error 0x%08lx\n", hres);
+
+  hres = SafeArrayCopy(sa, &sa2);
+  ok(hres == E_INVALIDARG,
+    "SafeArrayCopy with empty array should have failed with error E_INVALIDARG instead of 0x%08lx\n",
+    hres);
+  sa->cbElements = 16;
+  hres = SafeArrayCopy(sa, &sa2);
+  ok(hres == S_OK, "SafeArrayCopy failed with error 0x%08lx\n", hres);
+
+  SafeArrayDestroy(sa);
 }
 
 #define MKARRAY(low,num,typ) sab.lLbound = low; sab.cElements = num; \




More information about the wine-cvs mailing list