From e5daf3397839a7527a921a8edb9091e1655e484c Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Wed, 23 Dec 2015 17:47:48 +1100 Subject: [PATCH] oledb32: GetConversionSize shouldn't fail for null variants. If we have a NULL variant which will be converted to a non-fixed sized type (DBTYPE_WSTR) then we just return S_OK. Signed-off-by: Alistair Leslie-Hughes Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/oledb32/convert.c | 3 +++ dlls/oledb32/tests/convert.c | 39 +++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/dlls/oledb32/convert.c b/dlls/oledb32/convert.c index 891b31c1bd5..0a1518d9a92 100644 --- a/dlls/oledb32/convert.c +++ b/dlls/oledb32/convert.c @@ -1344,6 +1344,9 @@ static HRESULT WINAPI convert_GetConversionSize(IDataConvert* iface, if ((*dst_len = get_length(dst_type))) return S_OK; + if(src_type == DBTYPE_VARIANT && V_VT((VARIANT*)src) == VT_NULL) + return S_OK; + switch (dst_type) { case DBTYPE_STR: diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index a7854577a3a..46719b19197 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -2631,16 +2631,25 @@ static void test_getconversionsize(void) src_len = 20; V_VT(&var) = VT_BSTR; V_BSTR(&var) = SysAllocString(strW); - hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var); + hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_STR, &src_len, &dst_len, &var); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(dst_len == 5, "%ld\n", dst_len); + VariantClear(&var); + + src_len = 20; + V_VT(&var) = VT_I4; + V_I4(&var) = 4; + hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_STR, &src_len, &dst_len, &var); ok(hr == S_OK, "got 0x%08x\n", hr); - ok(dst_len == 2, "%ld\n", dst_len); VariantClear(&var); dst_len = 0; src_len = 20; - V_VT(&var) = VT_NULL; + V_VT(&var) = VT_BSTR; + V_BSTR(&var) = SysAllocString(strW); hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var); ok(hr == S_OK, "got 0x%08x\n", hr); + ok(dst_len == 2, "%ld\n", dst_len); VariantClear(&var); dst_len = 0; @@ -2655,6 +2664,30 @@ static void test_getconversionsize(void) ok(hr == S_OK, "got 0x%08x\n", hr); ok(dst_len == 1802, "%ld\n", dst_len); VariantClear(&var); + + /* On Windows, NULL variants being convert to a non-fixed sized type will return a dst_len of + * 110 but we aren't testing for this value. + */ + dst_len = 32; + V_VT(&var) = VT_NULL; + hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_I4, NULL, &dst_len, &var); + ok(dst_len == 4, "%ld\n", dst_len); + ok(hr == S_OK, "got 0x%08x\n", hr); + + V_VT(&var) = VT_NULL; + hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_STR, NULL, &dst_len, &var); + ok(hr == S_OK, "got 0x%08x\n", hr); + + V_VT(&var) = VT_NULL; + hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_WSTR, NULL, &dst_len, &var); + ok(hr == S_OK, "got 0x%08x\n", hr); + + src_len = 20; + V_VT(&var) = VT_NULL; + hr = IDataConvert_GetConversionSize(convert, DBTYPE_VARIANT, DBTYPE_BYTES, &src_len, &dst_len, &var); + ok(hr == S_OK, "got 0x%08x\n", hr); + VariantClear(&var); + } static void test_converttobytes(void)