oledb32: Fix conversion of strings with embedded '\0' to DBTYPE_STR | DBTYPE_BYREF.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2017-03-01 11:32:07 +00:00 committed by Alexandre Julliard
parent 853de70bc0
commit aedd6e951c
2 changed files with 34 additions and 2 deletions

View File

@ -876,13 +876,13 @@ static HRESULT WINAPI convert_DataConvert(IDataConvert* iface,
precision, scale, flags);
if(hr != S_OK) return hr;
length = WideCharToMultiByte(CP_ACP, 0, b, -1, NULL, 0, NULL, NULL);
length = WideCharToMultiByte(CP_ACP, 0, b, SysStringLen(b) + 1, NULL, 0, NULL, NULL);
*dst_len = length - 1; /* Doesn't include size for '\0' */
*dst_status = DBSTATUS_S_OK;
*d = CoTaskMemAlloc(length);
if(*d)
WideCharToMultiByte(CP_ACP, 0, b, -1, *d, length, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, b, SysStringLen(b) + 1, *d, length, NULL, NULL);
else
hr = E_OUTOFMEMORY;
SysFreeString(b);

View File

@ -2155,6 +2155,7 @@ static void test_converttobyrefstr(void)
DBSTATUS dst_status;
DBLENGTH dst_len;
static const WCHAR ten[] = {'1','0',0};
static const char withnull[] = "test\0ed";
BSTR b;
VARIANT v;
@ -2232,6 +2233,37 @@ static void test_converttobyrefstr(void)
ok(!lstrcmpA("10", dst), "got %s\n", dst);
CoTaskMemFree(dst);
memcpy(src, withnull, sizeof(withnull));
dst_len = 0x1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, sizeof(withnull), &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
ok(hr == S_OK, "got %08x\n", hr);
ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
ok(dst_len == 8, "got %ld\n", dst_len);
ok(!memcmp(withnull, dst, 8), "got %s\n", dst);
ok(dst[8] == 0, "got %02x\n", dst[8]);
CoTaskMemFree(dst);
memcpy(src, withnull, sizeof(withnull));
dst_len = 0x1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, 7, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
ok(hr == S_OK, "got %08x\n", hr);
ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
ok(dst_len == 7, "got %ld\n", dst_len);
ok(!memcmp(withnull, dst, 7), "got %s\n", dst);
ok(dst[7] == 0, "got %02x\n", dst[7]);
CoTaskMemFree(dst);
memcpy(src, withnull, sizeof(withnull));
dst_len = 0x1234;
hr = IDataConvert_DataConvert(convert, DBTYPE_STR, DBTYPE_STR | DBTYPE_BYREF, 6, &dst_len, src, &dst, sizeof(dst), 0, &dst_status, 0, 0, 0);
ok(hr == S_OK, "got %08x\n", hr);
ok(dst_status == DBSTATUS_S_OK, "got %08x\n", dst_status);
ok(dst_len == 6, "got %ld\n", dst_len);
ok(!memcmp(withnull, dst, 6), "got %s\n", dst);
ok(dst[6] == 0, "got %02x\n", dst[6]);
CoTaskMemFree(dst);
dst_len = 44;
V_VT(&v) = VT_NULL;
hr = IDataConvert_DataConvert(convert, DBTYPE_VARIANT, DBTYPE_STR | DBTYPE_BYREF, 0, &dst_len, &v, dst, sizeof(dst), 0, &dst_status, 0, 0, 0);