Skip to content

Commit

Permalink
windows: use WIN_UTF8ToStringW() for dialog titles
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 19, 2025
1 parent 43b54b3 commit 20ad2f3
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions src/dialog/windows/SDL_windowsdialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 20ad2f3

Please sign in to comment.