From 20ad2f30622cdf518c502e6fb8958b71314744c2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 19 Jan 2025 08:35:04 -0800 Subject: [PATCH] windows: use WIN_UTF8ToStringW() for dialog titles --- src/dialog/windows/SDL_windowsdialog.c | 36 ++------------------------ 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/dialog/windows/SDL_windowsdialog.c b/src/dialog/windows/SDL_windowsdialog.c index b52e8b3ba4b04..2de224feba642 100644 --- a/src/dialog/windows/SDL_windowsdialog.c +++ b/src/dialog/windows/SDL_windowsdialog.c @@ -196,28 +196,12 @@ void windows_ShowFileDialog(void *ptr) wchar_t *title_w = NULL; if (title) { - int title_len = (int) SDL_strlen(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)); - + title_w = WIN_UTF8ToStringW(title); if (!title_w) { SDL_free(filebuffer); callback(userdata, NULL, -1); return; } - - MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w, title_wlen); } OPENFILENAMEW dialog; @@ -432,27 +416,11 @@ void windows_ShowFolderDialog(void *ptr) wchar_t *title_w = NULL; if (title) { - int title_len = (int) SDL_strlen(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)); - + title_w = WIN_UTF8ToStringW(title); if (!title_w) { callback(userdata, NULL, -1); return; } - - MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w, title_wlen); } wchar_t buffer[MAX_PATH];