Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/propsys/propsys.spec | 2 +- dlls/propsys/propvar.c | 12 ++++++++++++ dlls/propsys/tests/propsys.c | 33 +++++++++++++++++++++++++++++++++ include/propvarutil.h | 1 + 4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/dlls/propsys/propsys.spec b/dlls/propsys/propsys.spec index d9347e27ae..8416b6dc74 100644 --- a/dlls/propsys/propsys.spec +++ b/dlls/propsys/propsys.spec @@ -111,7 +111,7 @@ @ stub PropVariantToBooleanVector @ stub PropVariantToBooleanVectorAlloc @ stub PropVariantToBooleanWithDefault -@ stub PropVariantToBuffer +@ stdcall PropVariantToBuffer(ptr ptr long) @ stdcall PropVariantToDouble(ptr ptr) @ stub PropVariantToDoubleVector @ stub PropVariantToDoubleVectorAlloc diff --git a/dlls/propsys/propvar.c b/dlls/propsys/propvar.c index 5950cc833b..6200e3e993 100644 --- a/dlls/propsys/propvar.c +++ b/dlls/propsys/propvar.c @@ -306,6 +306,18 @@ HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret) return hr; }
+HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb) +{ + TRACE("(%p, %p, %d)\n", propvarIn, ret, cb); + + if(cb > propvarIn->u.caub.cElems) + return E_FAIL; + + memcpy(ret, propvarIn->u.caub.pElems, cb); + + return S_OK; +} + HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch) { HRESULT hr = S_OK; diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c index 05cff65151..740e349bfb 100644 --- a/dlls/propsys/tests/propsys.c +++ b/dlls/propsys/tests/propsys.c @@ -1406,6 +1406,38 @@ static void test_PropVariantToString(void) PropVariantClear(&propvar); }
+static void test_PropVariantToBuffer(void) +{ + PROPVARIANT propvar; + HRESULT hr; + UINT8 data[] = {1,2,3,4,5,6,7,8,9,10}; + UINT8 buffer[256]; + + hr = InitPropVariantFromBuffer(data, 10, &propvar); + ok(hr == S_OK, "InitVariantFromBuffer failed 0x%08x.\n", hr); + hr = PropVariantToBuffer(&propvar, buffer, 10); + ok(hr == S_OK, "PropVariantToBuffer fail: 0x%08x.\n", hr); + ok(!memcmp(buffer, data, 10) && !buffer[10], "got wrong buffer.\n"); + memset(buffer, 0, sizeof(buffer)); + PropVariantClear(&propvar); + + hr = InitPropVariantFromBuffer(data, 10, &propvar); + ok(hr == S_OK, "InitVariantFromBuffer failed 0x%08x.\n", hr); + hr = PropVariantToBuffer(&propvar, buffer, 11); + ok(hr == E_FAIL, "PropVariantToBuffer fail: 0x%08x.\n", hr); + ok(!buffer[0], "got wrong buffer.\n"); + memset(buffer, 0, sizeof(buffer)); + PropVariantClear(&propvar); + + hr = InitPropVariantFromBuffer(data, 10, &propvar); + ok(hr == S_OK, "InitVariantFromBuffer failed 0x%08x.\n", hr); + hr = PropVariantToBuffer(&propvar, buffer, 9); + ok(hr == S_OK, "PropVariantToBuffer fail: 0x%08x.\n", hr); + ok(!memcmp(buffer, data, 9) && !buffer[9], "got wrong buffer.\n"); + memset(buffer, 0, sizeof(buffer)); + PropVariantClear(&propvar); +} + START_TEST(propsys) { test_PSStringFromPropertyKey(); @@ -1423,4 +1455,5 @@ START_TEST(propsys) test_InitPropVariantFromCLSID(); test_PropVariantToDouble(); test_PropVariantToString(); + test_PropVariantToBuffer(); } diff --git a/include/propvarutil.h b/include/propvarutil.h index 4fb12d87eb..a4eedefdb6 100644 --- a/include/propvarutil.h +++ b/include/propvarutil.h @@ -79,6 +79,7 @@ HRESULT WINAPI PropVariantToUInt16(REFPROPVARIANT propvarIn, USHORT *ret); HRESULT WINAPI PropVariantToUInt32(REFPROPVARIANT propvarIn, ULONG *ret); HRESULT WINAPI PropVariantToUInt64(REFPROPVARIANT propvarIn, ULONGLONG *ret); HRESULT WINAPI PropVariantToBoolean(REFPROPVARIANT propvarIn, BOOL *ret); +HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb); HRESULT WINAPI PropVariantToString(REFPROPVARIANT propvarIn, PWSTR ret, UINT cch); PCWSTR WINAPI PropVariantToStringWithDefault(REFPROPVARIANT propvarIn, LPCWSTR pszDefault);
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=47679
Your paranoid android.
=== wvistau64 (64 bit report) ===
Report errors: propsys:propsys crashed (c0000374)
=== w2008s64 (64 bit report) ===
Report errors: propsys:propsys crashed (c0000374)
=== w7pro64 (64 bit report) ===
Report errors: propsys:propsys crashed (c0000374)
=== w864 (64 bit report) ===
Report errors: propsys:propsys crashed (c0000374)
=== w1064 (64 bit report) ===
Report errors: propsys:propsys crashed (c0000374)
Jactry Zeng jzeng@codeweavers.com wrote:
+HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void *ret, UINT cb) +{
- TRACE("(%p, %p, %d)\n", propvarIn, ret, cb);
- if(cb > propvarIn->u.caub.cElems)
return E_FAIL;
- memcpy(ret, propvarIn->u.caub.pElems, cb);
- return S_OK;
+}
What happens when NULL and/or 0 are passed in?
Hi Dmitry,
On Fri, Feb 15, 2019 at 3:42 AM Dmitry Timoshkov dmitry@baikal.ru wrote:
Jactry Zeng jzeng@codeweavers.com wrote:
+HRESULT WINAPI PropVariantToBuffer(REFPROPVARIANT propvarIn, void
*ret, UINT cb)
+{
- TRACE("(%p, %p, %d)\n", propvarIn, ret, cb);
- if(cb > propvarIn->u.caub.cElems)
return E_FAIL;
- memcpy(ret, propvarIn->u.caub.pElems, cb);
- return S_OK;
+}
What happens when NULL and/or 0 are passed in?
I sent another try and added a test for this case in it. Thanks for review and comment!