diff options
Diffstat (limited to 'src/utilcode/fstring.cpp')
-rw-r--r-- | src/utilcode/fstring.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/utilcode/fstring.cpp b/src/utilcode/fstring.cpp index 33aa346a9c..1165ecaac0 100644 --- a/src/utilcode/fstring.cpp +++ b/src/utilcode/fstring.cpp @@ -73,6 +73,9 @@ HRESULT Unicode_Utf8_Length(__in_z LPCWSTR pString, __out bool * pAllAscii, __ou return HRESULT_FROM_GetLastError(); } + // Remove the count of null terminator, to be consistent with the all-ASCII case. + --*pLength; + if (*pLength > MAX_LENGTH) { return COR_E_OVERFLOW; @@ -129,7 +132,7 @@ HRESULT Unicode_Utf8(__in_z LPCWSTR pString, bool allAscii, __out_z LPSTR pBuffe } else { - length = WszWideCharToMultiByte(CP_UTF8, 0, pString, -1, pBuffer, (int) length, NULL, NULL); + length = WszWideCharToMultiByte(CP_UTF8, 0, pString, -1, pBuffer, (int) length + 1, NULL, NULL); if (length == 0) { @@ -190,6 +193,9 @@ HRESULT Utf8_Unicode_Length(__in_z LPCSTR pString, __out bool * pAllAscii, __out return HRESULT_FROM_GetLastError(); } + // Remove the count of null terminator, to be consistent with the all-ASCII case. + --*pLength; + if (* pLength > MAX_LENGTH) { return COR_E_OVERFLOW; @@ -200,7 +206,7 @@ HRESULT Utf8_Unicode_Length(__in_z LPCSTR pString, __out bool * pAllAscii, __out } -// UTF8 to ANSI +// UTF8 to Unicode HRESULT Utf8_Unicode(__in_z LPCSTR pString, bool allAscii, __out_z LPWSTR pBuffer, DWORD length) { @@ -247,7 +253,7 @@ HRESULT Utf8_Unicode(__in_z LPCSTR pString, bool allAscii, __out_z LPWSTR pBuffe } else { - length = WszMultiByteToWideChar(CP_UTF8, 0, pString, -1, pBuffer, (int) length); + length = WszMultiByteToWideChar(CP_UTF8, 0, pString, -1, pBuffer, (int) length + 1); if (length == 0) { |