windows: don't dupstr if setlocale returns NULL

This commit is contained in:
nhmall
2023-06-30 15:14:09 -04:00
parent 4d9bfccc90
commit 52dcd101e4

View File

@@ -1911,12 +1911,16 @@ tty_utf8graphics_fixup(void)
{
CONSOLE_FONT_INFOEX console_font_info;
if ((tty_procs.wincap2 & WC2_U_UTF8STR) && SYMHANDLING(H_UTF8)) {
if (!console.hConOut)
char *tmpstr = 0;
if (!console.hConOut)
console.hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
/* the locale */
if (console.localestr)
free(console.localestr);
console.localestr = dupstr(setlocale(LC_ALL, ".UTF8"));
tmpstr = setlocale(LC_ALL, ".UTF8");
if (tmpstr)
console.localestr = dupstr(tmpstr);
/* the code page */
SetConsoleOutputCP(65001);
console.code_page = GetConsoleOutputCP();