mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[COMSUPP]: Fix string length computations.
svn path=/trunk/; revision=69582
This commit is contained in:
parent
698212a5a5
commit
4371669b69
1 changed files with 8 additions and 9 deletions
|
@ -62,13 +62,12 @@ BSTR WINAPI ConvertStringToBSTR(const char *pSrc)
|
||||||
|
|
||||||
if (!pSrc) return NULL;
|
if (!pSrc) return NULL;
|
||||||
|
|
||||||
/* Compute the needed size without the NULL terminator */
|
/* Compute the needed size with the NULL terminator */
|
||||||
cwch = ::MultiByteToWideChar(CP_ACP /* CP_UTF8 */, 0, pSrc, -1, NULL, 0);
|
cwch = ::MultiByteToWideChar(CP_ACP /* CP_UTF8 */, 0, pSrc, -1, NULL, 0);
|
||||||
if (cwch == 0) return NULL;
|
if (cwch == 0) return NULL;
|
||||||
cwch--;
|
|
||||||
|
|
||||||
/* Allocate the BSTR */
|
/* Allocate the BSTR (without the NULL terminator) */
|
||||||
wsOut = ::SysAllocStringLen(NULL, cwch);
|
wsOut = ::SysAllocStringLen(NULL, cwch - 1);
|
||||||
if (!wsOut)
|
if (!wsOut)
|
||||||
{
|
{
|
||||||
::_com_issue_error(HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY));
|
::_com_issue_error(HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY));
|
||||||
|
@ -97,11 +96,11 @@ char* WINAPI ConvertBSTRToString(BSTR pSrc)
|
||||||
|
|
||||||
if (!pSrc) return NULL;
|
if (!pSrc) return NULL;
|
||||||
|
|
||||||
/* Retrieve the size of the BSTR without the NULL terminator */
|
/* Retrieve the size of the BSTR with the NULL terminator */
|
||||||
cwch = ::SysStringLen(pSrc);
|
cwch = ::SysStringLen(pSrc) + 1;
|
||||||
|
|
||||||
/* Compute the needed size with the NULL terminator */
|
/* Compute the needed size with the NULL terminator */
|
||||||
cb = ::WideCharToMultiByte(CP_ACP /* CP_UTF8 */, 0, pSrc, cwch + 1, NULL, 0, NULL, NULL);
|
cb = ::WideCharToMultiByte(CP_ACP /* CP_UTF8 */, 0, pSrc, cwch, NULL, 0, NULL, NULL);
|
||||||
if (cb == 0)
|
if (cb == 0)
|
||||||
{
|
{
|
||||||
cwch = ::GetLastError();
|
cwch = ::GetLastError();
|
||||||
|
@ -118,8 +117,8 @@ char* WINAPI ConvertBSTRToString(BSTR pSrc)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert the string and NULL-terminate */
|
/* Convert the string and NULL-terminate */
|
||||||
szOut[cb - 1] = '\0';
|
szOut[cb - 1] = '\0';
|
||||||
if (::WideCharToMultiByte(CP_ACP /* CP_UTF8 */, 0, pSrc, cwch + 1, szOut, cb, NULL, NULL) == 0)
|
if (::WideCharToMultiByte(CP_ACP /* CP_UTF8 */, 0, pSrc, cwch, szOut, cb, NULL, NULL) == 0)
|
||||||
{
|
{
|
||||||
/* We failed, clean everything up */
|
/* We failed, clean everything up */
|
||||||
cwch = ::GetLastError();
|
cwch = ::GetLastError();
|
||||||
|
|
Loading…
Reference in a new issue