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