From 17ec77f19e7acd4d8728208c16892146f58109e3 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Wed, 3 May 2006 17:30:35 +0100 Subject: [PATCH] oleaut32: Alignment fixes for safearrays. --- dlls/oleaut32/tests/usrmarshal.c | 21 +++++++++++++++++++++ dlls/oleaut32/usrmarshal.c | 17 ++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dlls/oleaut32/tests/usrmarshal.c b/dlls/oleaut32/tests/usrmarshal.c index 3f417e1a04e..1659407cd45 100644 --- a/dlls/oleaut32/tests/usrmarshal.c +++ b/dlls/oleaut32/tests/usrmarshal.c @@ -164,6 +164,8 @@ static void test_marshal_LPSAFEARRAY(void) *(DWORD *)lpsa->pvData = 0xcafebabe; lpsa->cLocks = 7; + size = LPSAFEARRAY_UserSize(&umcb.Flags, 1, &lpsa); + ok(size == 68, "size should be 68 bytes, not %ld\n", size); size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa); ok(size == 64, "size should be 64 bytes, not %ld\n", size); buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size); @@ -196,6 +198,25 @@ static void test_marshal_LPSAFEARRAY(void) LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2); } HeapFree(GetProcessHeap(), 0, buffer); + + sab.lLbound = 5; + sab.cElements = 10; + + lpsa = SafeArrayCreate(VT_R8, 1, &sab); + *(double *)lpsa->pvData = 3.1415; + + lpsa->cLocks = 7; + size = LPSAFEARRAY_UserSize(&umcb.Flags, 1, &lpsa); + ok(size == 128, "size should be 128 bytes, not %ld\n", size); + size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa); + ok(size == 128, "size should be 128 bytes, not %ld\n", size); + buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size); + LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa); + + check_safearray(buffer, lpsa); + + HeapFree(GetProcessHeap(), 0, buffer); + SafeArrayDestroy(lpsa); } static void check_bstr(void *buffer, BSTR b) diff --git a/dlls/oleaut32/usrmarshal.c b/dlls/oleaut32/usrmarshal.c index 05aef80450b..c4519a18146 100644 --- a/dlls/oleaut32/usrmarshal.c +++ b/dlls/oleaut32/usrmarshal.c @@ -662,6 +662,7 @@ unsigned long WINAPI LPSAFEARRAY_UserSize(unsigned long *pFlags, unsigned long S TRACE("("); dump_user_flags(pFlags); TRACE(", %ld, %p\n", StartingSize, *ppsa); + ALIGN_LENGTH(size, 3); size += sizeof(ULONG_PTR); if (*ppsa) { @@ -726,10 +727,12 @@ unsigned long WINAPI LPSAFEARRAY_UserSize(unsigned long *pFlags, unsigned long S } break; } + case SF_I8: + ALIGN_LENGTH(size, 7); + /* fallthrough */ case SF_I1: case SF_I2: case SF_I4: - case SF_I8: size += ulCellCount * psa->cbElements; break; default: @@ -747,6 +750,7 @@ unsigned char * WINAPI LPSAFEARRAY_UserMarshal(unsigned long *pFlags, unsigned c TRACE("("); dump_user_flags(pFlags); TRACE(", %p, &%p\n", Buffer, *ppsa); + ALIGN_POINTER(Buffer, 3); *(ULONG_PTR *)Buffer = *ppsa ? TRUE : FALSE; Buffer += sizeof(ULONG_PTR); if (*ppsa) @@ -836,10 +840,13 @@ unsigned char * WINAPI LPSAFEARRAY_UserMarshal(unsigned long *pFlags, unsigned c } break; } + + case SF_I8: + ALIGN_POINTER(Buffer, 7); + /* fallthrough */ case SF_I1: case SF_I2: case SF_I4: - case SF_I8: /* Just copy the data over */ memcpy(Buffer, psa->pvData, ulCellCount * psa->cbElements); Buffer += ulCellCount * psa->cbElements; @@ -871,6 +878,7 @@ unsigned char * WINAPI LPSAFEARRAY_UserUnmarshal(unsigned long *pFlags, unsigned TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", Buffer, ppsa); + ALIGN_POINTER(Buffer, 3); ptr = *(ULONG_PTR *)Buffer; Buffer += sizeof(ULONG_PTR); @@ -964,10 +972,13 @@ unsigned char * WINAPI LPSAFEARRAY_UserUnmarshal(unsigned long *pFlags, unsigned break; } + + case SF_I8: + ALIGN_POINTER(Buffer, 7); + /* fallthrough */ case SF_I1: case SF_I2: case SF_I4: - case SF_I8: /* Just copy the data over */ memcpy((*ppsa)->pvData, Buffer, cell_count * (*ppsa)->cbElements); Buffer += cell_count * (*ppsa)->cbElements;