https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fec35dc89386eb02761b5…
commit fec35dc89386eb02761b5e12573de164fb5904c9
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Oct 15 10:31:08 2021 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Oct 15 10:31:08 2021 +0900
[IMM32] Improve IchWideFromAnsi and IchAnsiFromWide (#4028)
- Use LONG instead of DWORD for indexing and counting the characters.
- Use the sign for the loop condition.
- Add NUL check.
CORE-11700
---
dll/win32/imm32/precomp.h | 4 ++--
dll/win32/imm32/utils.c | 28 +++++++++++-----------------
2 files changed, 13 insertions(+), 19 deletions(-)
diff --git a/dll/win32/imm32/precomp.h b/dll/win32/imm32/precomp.h
index 17f46493c88..35d03332835 100644
--- a/dll/win32/imm32/precomp.h
+++ b/dll/win32/imm32/precomp.h
@@ -81,8 +81,8 @@ LPVOID APIENTRY Imm32HeapAlloc(DWORD dwFlags, DWORD dwBytes);
LPWSTR APIENTRY Imm32WideFromAnsi(LPCSTR pszA);
LPSTR APIENTRY Imm32AnsiFromWide(LPCWSTR pszW);
-DWORD APIENTRY IchWideFromAnsi(DWORD cchAnsi, LPCSTR pchAnsi, UINT uCodePage);
-DWORD APIENTRY IchAnsiFromWide(DWORD cchWide, LPCWSTR pchWide, UINT uCodePage);
+LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage);
+LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage);
PIMEDPI APIENTRY ImmLockOrLoadImeDpi(HKL hKL);
LPINPUTCONTEXT APIENTRY Imm32LockIMCEx(HIMC hIMC, BOOL fSelect);
BOOL APIENTRY Imm32ReleaseIME(HKL hKL);
diff --git a/dll/win32/imm32/utils.c b/dll/win32/imm32/utils.c
index 20790f78110..6dddd9df22a 100644
--- a/dll/win32/imm32/utils.c
+++ b/dll/win32/imm32/utils.c
@@ -50,23 +50,16 @@ LPSTR APIENTRY Imm32AnsiFromWide(LPCWSTR pszW)
return pszA;
}
-DWORD APIENTRY IchWideFromAnsi(DWORD cchAnsi, LPCSTR pchAnsi, UINT uCodePage)
+/* Converts the character index */
+LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage)
{
- DWORD cchWide;
- for (cchWide = 0; cchAnsi; ++cchWide)
+ LONG cchWide;
+ for (cchWide = 0; cchAnsi > 0; ++cchWide)
{
- if (IsDBCSLeadByteEx(uCodePage, *pchAnsi))
+ if (IsDBCSLeadByteEx(uCodePage, *pchAnsi) && pchAnsi[1])
{
- if (cchAnsi <= 1)
- {
- ++cchWide;
- break;
- }
- else
- {
- cchAnsi -= 2;
- pchAnsi += 2;
- }
+ cchAnsi -= 2;
+ pchAnsi += 2;
}
else
{
@@ -77,10 +70,11 @@ DWORD APIENTRY IchWideFromAnsi(DWORD cchAnsi, LPCSTR pchAnsi, UINT
uCodePage)
return cchWide;
}
-DWORD APIENTRY IchAnsiFromWide(DWORD cchWide, LPCWSTR pchWide, UINT uCodePage)
+/* Converts the character index */
+LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage)
{
- DWORD cb, cchAnsi;
- for (cchAnsi = 0; cchWide; ++cchAnsi, ++pchWide, --cchWide)
+ LONG cb, cchAnsi;
+ for (cchAnsi = 0; cchWide > 0; ++cchAnsi, ++pchWide, --cchWide)
{
cb = WideCharToMultiByte(uCodePage, 0, pchWide, 1, NULL, 0, NULL, NULL);
if (cb > 1)