oleaut32: Fix copying an array of 0 elements
André Hentschel
nerv at dawncrow.de
Mon Feb 7 12:57:31 CST 2011
might help bug 26005
---
dlls/oleaut32/safearray.c | 13 ++++++-------
dlls/oleaut32/tests/safearray.c | 22 +++++++++++++++++++---
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/dlls/oleaut32/safearray.c b/dlls/oleaut32/safearray.c
index dd00cfd..65739e9 100644
--- a/dlls/oleaut32/safearray.c
+++ b/dlls/oleaut32/safearray.c
@@ -1355,12 +1355,6 @@ HRESULT WINAPI SafeArrayCopy(SAFEARRAY *psa, SAFEARRAY **ppsaOut)
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;
@@ -1391,7 +1385,12 @@ HRESULT WINAPI SafeArrayCopy(SAFEARRAY *psa, SAFEARRAY **ppsaOut)
hRet = SAFEARRAY_CopyData(psa, *ppsaOut);
if (SUCCEEDED(hRet))
- return hRet;
+ {
+ if (!psa->cbElements)
+ return E_INVALIDARG;
+ else
+ return hRet;
+ }
SAFEARRAY_Free((*ppsaOut)->pvData);
}
diff --git a/dlls/oleaut32/tests/safearray.c b/dlls/oleaut32/tests/safearray.c
index 97ba9dd..dd6f94c 100644
--- a/dlls/oleaut32/tests/safearray.c
+++ b/dlls/oleaut32/tests/safearray.c
@@ -1590,13 +1590,29 @@ static void test_SafeArrayCopy(void)
hres = SafeArrayAllocDescriptor(1, &sa);
ok(hres == S_OK, "SafeArrayAllocDescriptor failed with error 0x%08x\n", hres);
+ sa->cbElements = 16;
+ hres = SafeArrayCopy(sa, &sa2);
+ ok(hres == S_OK, "SafeArrayCopy failed with error 0x%08x\n", hres);
+ ok(sa != sa2, "SafeArrayCopy performed shallow copy\n");
+
+ hres = SafeArrayDestroy(sa2);
+ ok(hres == S_OK, "got 0x%08x\n", hres);
+ hres = SafeArrayDestroy(sa);
+ ok(hres == S_OK, "got 0x%08x\n", hres);
+
+ hres = SafeArrayCopy(NULL, &sa2);
+ ok(hres == S_OK, "SafeArrayCopy failed with error 0x%08x\n", hres);
+ ok(!sa2, "SafeArrayCopy returned NULL for output array\n");
+
+ hres = SafeArrayAllocDescriptor(1, &sa);
+ ok(hres == S_OK, "SafeArrayAllocDescriptor failed with error 0x%08x\n", hres);
+
hres = SafeArrayCopy(sa, &sa2);
ok(hres == E_INVALIDARG,
"SafeArrayCopy with empty array should have failed with error E_INVALIDARG instead of 0x%08x\n",
hres);
- sa->cbElements = 16;
- hres = SafeArrayCopy(sa, &sa2);
- ok(hres == S_OK, "SafeArrayCopy failed with error 0x%08x\n", hres);
+ ok(sa != sa2, "SafeArrayCopy performed shallow copy\n");
+ ok(sa2->cbElements == sa->cbElements, "SafeArrayCopy with empty array copied wrong Element count\n");
hres = SafeArrayDestroy(sa2);
ok(hres == S_OK, "got 0x%08x\n", hres);
--
Best Regards, André Hentschel
More information about the wine-patches
mailing list