From 37e2acb205957bd7120274a73abba9323994aa21 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Wed, 13 Jan 2016 09:51:23 +0100 Subject: [PATCH] oleaut32: Pass safearray from VARIANT_UserUnmarshal to LPSAFEARRAY_UserUnmarshal so it can be reused. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/oleaut32/tests/usrmarshal.c | 8 ++------ dlls/oleaut32/usrmarshal.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dlls/oleaut32/tests/usrmarshal.c b/dlls/oleaut32/tests/usrmarshal.c index d4d7d5312de..e5fb58cd401 100644 --- a/dlls/oleaut32/tests/usrmarshal.c +++ b/dlls/oleaut32/tests/usrmarshal.c @@ -1370,13 +1370,9 @@ static void test_marshal_VARIANT(void) next = VARIANT_UserUnmarshal(&umcb.Flags, buffer, &v2); ok(next == buffer + expected, "got %p expect %p\n", next, buffer + expected); ok(V_VT(&v) == V_VT(&v2), "got vt %d expect %d\n", V_VT(&v), V_VT(&v2)); - todo_wine ok(lpsa2 == lpsa_copy, "safearray should be reused\n"); + ok(lpsa2 == lpsa_copy, "safearray should be reused\n"); todo_wine ok(mem == lpsa2->pvData, "safearray data should be reused\n"); - if(lpsa2 != lpsa_copy) - { - lpsa_copy->fFeatures &= ~FADF_STATIC; - SafeArrayDestroy(lpsa_copy); - } + if(mem != lpsa2->pvData) CoTaskMemFree(mem); ok(SafeArrayGetDim(*V_ARRAYREF(&v)) == SafeArrayGetDim(*V_ARRAYREF(&v2)), "array dims differ\n"); SafeArrayGetLBound(*V_ARRAYREF(&v), 1, &bound); SafeArrayGetLBound(*V_ARRAYREF(&v2), 1, &bound2); diff --git a/dlls/oleaut32/usrmarshal.c b/dlls/oleaut32/usrmarshal.c index d66d42a483d..02f5f34d0ef 100644 --- a/dlls/oleaut32/usrmarshal.c +++ b/dlls/oleaut32/usrmarshal.c @@ -520,10 +520,16 @@ unsigned char * WINAPI VARIANT_UserUnmarshal(ULONG *pFlags, unsigned char *Buffe { VariantClear(pvar); V_BYREF(pvar) = CoTaskMemAlloc(mem_size); + memset(V_BYREF(pvar), 0, mem_size); } else if (!V_BYREF(pvar)) + { V_BYREF(pvar) = CoTaskMemAlloc(mem_size); - memcpy(V_BYREF(pvar), Pos, type_size); + memset(V_BYREF(pvar), 0, mem_size); + } + + if(!(header->vt & VT_ARRAY)) + memcpy(V_BYREF(pvar), Pos, type_size); if((header->vt & VT_TYPEMASK) != VT_VARIANT) Pos += type_size; else @@ -532,7 +538,9 @@ unsigned char * WINAPI VARIANT_UserUnmarshal(ULONG *pFlags, unsigned char *Buffe else { VariantClear(pvar); - if((header->vt & VT_TYPEMASK) == VT_DECIMAL) + if(header->vt & VT_ARRAY) + V_ARRAY(pvar) = NULL; + else if((header->vt & VT_TYPEMASK) == VT_DECIMAL) memcpy(pvar, Pos, type_size); else memcpy(&pvar->n1.n2.n3, Pos, type_size); @@ -963,6 +971,7 @@ unsigned char * WINAPI LPSAFEARRAY_UserUnmarshal(ULONG *pFlags, unsigned char *B if (!ptr) { + SafeArrayDestroy(*ppsa); *ppsa = NULL; TRACE("NULL safe array unmarshaled\n"); @@ -1001,11 +1010,13 @@ unsigned char * WINAPI LPSAFEARRAY_UserUnmarshal(ULONG *pFlags, unsigned char *B if(vt) { + SafeArrayDestroy(*ppsa); *ppsa = SafeArrayCreateEx(vt, wiresa->cDims, wiresab, NULL); if (!*ppsa) RpcRaiseException(E_OUTOFMEMORY); } else { + SafeArrayDestroy(*ppsa); if (FAILED(SafeArrayAllocDescriptor(wiresa->cDims, ppsa))) RpcRaiseException(E_OUTOFMEMORY); memcpy((*ppsa)->rgsabound, wiresab, sizeof(SAFEARRAYBOUND) * wiresa->cDims);