James Hawkins : mlang: Reimplement ConvertINetMultiByteToUnicode.
Alexandre Julliard
julliard at winehq.org
Tue Jul 8 06:11:12 CDT 2008
Module: wine
Branch: master
Commit: 4e3ce9f887d01bdd46f77a0ec6eee8ad7dbc8ad1
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4e3ce9f887d01bdd46f77a0ec6eee8ad7dbc8ad1
Author: James Hawkins <jhawkins at codeweavers.com>
Date: Tue Jul 8 00:01:21 2008 -0500
mlang: Reimplement ConvertINetMultiByteToUnicode.
---
dlls/mlang/mlang.c | 57 +++++++++++++++++++++++++++++++--------------------
1 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/dlls/mlang/mlang.c b/dlls/mlang/mlang.c
index 2f73f1f..14f881e 100644
--- a/dlls/mlang/mlang.c
+++ b/dlls/mlang/mlang.c
@@ -546,50 +546,63 @@ HRESULT WINAPI ConvertINetUnicodeToMultiByte(
LPSTR pDstStr,
LPINT pcDstSize)
{
-
+ INT destsz, size;
INT src_len = -1;
TRACE("%p %d %s %p %p %p\n", pdwMode, dwEncoding,
debugstr_w(pSrcStr), pcSrcSize, pDstStr, pcDstSize);
if (!pcDstSize)
- return E_FAIL;
+ return S_OK;
if (!pcSrcSize)
pcSrcSize = &src_len;
- if (!*pcSrcSize)
- {
- *pcDstSize = 0;
+ destsz = (pDstStr) ? *pcDstSize : 0;
+ *pcDstSize = 0;
+
+ if (!pSrcStr || !*pcSrcSize)
return S_OK;
- }
- switch (dwEncoding)
+ if (*pcSrcSize == -1)
+ *pcSrcSize = lstrlenW(pSrcStr);
+
+ if (dwEncoding == CP_UNICODE)
{
- case CP_UNICODE:
if (*pcSrcSize == -1)
*pcSrcSize = lstrlenW(pSrcStr);
- *pcDstSize = min(*pcSrcSize * sizeof(WCHAR), *pcDstSize);
+
+ size = min(*pcSrcSize, destsz) * sizeof(WCHAR);
if (pDstStr)
- memmove(pDstStr, pSrcStr, *pcDstSize);
- break;
+ memmove(pDstStr, pSrcStr, size);
- default:
- if (*pcSrcSize == -1)
- *pcSrcSize = lstrlenW(pSrcStr);
+ if (size >= destsz)
+ goto fail;
+ }
+ else
+ {
+ size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
+ NULL, 0, NULL, NULL);
+ if (!size)
+ goto fail;
if (pDstStr)
- *pcDstSize = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize, NULL, NULL);
- else
- *pcDstSize = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize, NULL, 0, NULL, NULL);
- break;
+ {
+ size = min(size, destsz);
+ size = WideCharToMultiByte(dwEncoding, 0, pSrcStr, *pcSrcSize,
+ pDstStr, destsz, NULL, NULL);
+ if (!size)
+ goto fail;
+ }
}
-
- if (!*pcDstSize)
- return E_FAIL;
-
+ *pcDstSize = size;
return S_OK;
+
+fail:
+ *pcSrcSize = 0;
+ *pcDstSize = 0;
+ return E_FAIL;
}
HRESULT WINAPI ConvertINetString(
More information about the wine-cvs
mailing list