From 46dd77fdb585bab4db2204fe10ebdabc6cc327d9 Mon Sep 17 00:00:00 2001 From: dolphin6k Date: Sat, 6 Nov 2021 01:00:18 +0900 Subject: [PATCH] Reverted to mtw(). (MultiByteToWideChar() was not safe for the labels on other versions of Windows.) --- src/tuxpaint.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 9840d47c5..810e00f2b 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -341,6 +341,28 @@ typedef struct safer_dirent #undef max #define mkdir(path,access) _mkdir(path) +static void mtw(wchar_t * wtok, char *tok, size_t size) +{ + /* workaround using iconv to get a functionallity somewhat approximate as mbstowcs() */ + Uint16 *ui16; + + ui16 = malloc(size); + char *wrptr = (char *)ui16; + size_t in, out, n; + iconv_t trans; + + in = size; + out = size; + n = size / sizeof(wchar_t); + + trans = iconv_open("WCHAR_T", "UTF-8"); + iconv(trans, (char **)&tok, &in, &wrptr, &out); + *((wchar_t *) wrptr) = L'\0'; + swprintf(wtok, n, L"%ls", ui16); + free(ui16); + iconv_close(trans); +} + extern int win32_trash(const char *path); #undef iswprint @@ -22560,7 +22582,7 @@ static void load_info_about_label_surface(FILE * lfi) tmpstr = malloc(1024); wtmpstr = malloc(1024); fgets(tmpstr, 1024, lfi); - MultiByteToWideChar(CP_UTF8,MB_COMPOSITE,tmpstr,-1,wtmpstr,1024); + mtw(wtmpstr, tmpstr, 1024); for (l = 0; l < new_node->save_texttool_len; l++) { new_node->save_texttool_str[l] = wtmpstr[l];