summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Brad Hughes <bradhugh@outlook.com>2016-03-22 21:15:46 -0400
committer Brad Hughes <bradhugh@outlook.com>2016-03-22 21:15:46 -0400
commit1c7f05a833f3e16a3f5085349e248e803b0d5068 (patch)
treec7bfa5a0aa3eca8c4808fdb1bc3ef2b4d895939c
parente7c1d090004d9b42840b34725f99e0501b713ae9 (diff)
Get max char size from ANSI codepage instead of IsDBCSLeadChar()
-rw-r--r--src/osd/strconv.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/osd/strconv.cpp b/src/osd/strconv.cpp
index ea1da56cc5a..2f4809e529d 100644
--- a/src/osd/strconv.cpp
+++ b/src/osd/strconv.cpp
@@ -109,13 +109,23 @@ char *utf8_from_wstring(const WCHAR *wstring)
int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
{
WCHAR wch;
+ CPINFO cp;
- count = MIN(count, IsDBCSLeadByte(*osdchar) ? 2 : 1);
- if (MultiByteToWideChar(CP_ACP, 0, osdchar, (DWORD)count, &wch, 1) != 0)
- *uchar = wch;
- else
- *uchar = 0;
- return (int) count;
+ if (!GetCPInfo(CP_ACP, &cp))
+ goto error;
+
+ // The multibyte char can't be bigger than the max character size
+ count = MIN(count, cp.MaxCharSize);
+
+ if (!MultiByteToWideChar(CP_ACP, 0, osdchar, static_cast<DWORD>(count), &wch, 1) != 0)
+ goto error;
+
+ *uchar = wch;
+ return static_cast<int>(count);
+
+error:
+ *uchar = 0;
+ return static_cast<int>(count);
}
#else