From 1c7f05a833f3e16a3f5085349e248e803b0d5068 Mon Sep 17 00:00:00 2001 From: Brad Hughes Date: Tue, 22 Mar 2016 21:15:46 -0400 Subject: [PATCH] Get max char size from ANSI codepage instead of IsDBCSLeadChar() --- src/osd/strconv.cpp | 22 ++++++++++++++++------ 1 file 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(count), &wch, 1) != 0) + goto error; + + *uchar = wch; + return static_cast(count); + +error: + *uchar = 0; + return static_cast(count); } #else