windows: use WIN_UTF8ToStringW() for dialog titles

This commit is contained in:
Sam Lantinga
2025-01-19 08:35:04 -08:00
parent 78023500fa
commit 3afd1e7eaa

View File

@@ -196,28 +196,12 @@ void windows_ShowFileDialog(void *ptr)
wchar_t *title_w = NULL; wchar_t *title_w = NULL;
if (title) { if (title) {
int title_len = (int) SDL_strlen(title); title_w = WIN_UTF8ToStringW(title);
/* If the title is longer than 2GB, it might be exploitable. */
if (title_len < 0) {
title_len = 0;
}
int title_wlen = MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
if (title_wlen < 0) {
title_wlen = 0;
}
title_w = (wchar_t *)SDL_malloc(title_wlen * sizeof(wchar_t));
if (!title_w) { if (!title_w) {
SDL_free(filebuffer); SDL_free(filebuffer);
callback(userdata, NULL, -1); callback(userdata, NULL, -1);
return; return;
} }
MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w, title_wlen);
} }
OPENFILENAMEW dialog; OPENFILENAMEW dialog;
@@ -432,27 +416,11 @@ void windows_ShowFolderDialog(void *ptr)
wchar_t *title_w = NULL; wchar_t *title_w = NULL;
if (title) { if (title) {
int title_len = (int) SDL_strlen(title); title_w = WIN_UTF8ToStringW(title);
/* If the title is longer than 2GB, it might be exploitable. */
if (title_len < 0) {
title_len = 0;
}
int title_wlen = MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
if (title_wlen < 0) {
title_wlen = 0;
}
title_w = (wchar_t *)SDL_malloc(title_wlen * sizeof(wchar_t));
if (!title_w) { if (!title_w) {
callback(userdata, NULL, -1); callback(userdata, NULL, -1);
return; return;
} }
MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w, title_wlen);
} }
wchar_t buffer[MAX_PATH]; wchar_t buffer[MAX_PATH];