mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Fix memory corruption in ImFileOpen on Windows when ImWchar is 32-bit (IMGUI_USE_WCHAR32 is set)
Ref issue 4149
This commit is contained in:
parent
c28be6ffce
commit
11083874bc
@ -1819,12 +1819,12 @@ ImFileHandle ImFileOpen(ImStrv filename, ImStrv mode)
|
|||||||
// Previously we used ImTextCountCharsFromUtf8/ImTextStrFromUtf8 here but we now need to support ImWchar16 and ImWchar32!
|
// Previously we used ImTextCountCharsFromUtf8/ImTextStrFromUtf8 here but we now need to support ImWchar16 and ImWchar32!
|
||||||
const int filename_wsize = ::MultiByteToWideChar(CP_UTF8, 0, filename.Begin, (int)filename.length(), NULL, 0);
|
const int filename_wsize = ::MultiByteToWideChar(CP_UTF8, 0, filename.Begin, (int)filename.length(), NULL, 0);
|
||||||
const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode.Begin, (int)mode.length(), NULL, 0);
|
const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode.Begin, (int)mode.length(), NULL, 0);
|
||||||
ImVector<ImWchar> buf;
|
ImVector<wchar_t> buf;
|
||||||
buf.resize(filename_wsize + 1 + mode_wsize + 1);
|
buf.resize(filename_wsize + 1 + mode_wsize + 1);
|
||||||
::MultiByteToWideChar(CP_UTF8, 0, filename.Begin, (int)filename.length(), (wchar_t*)&buf[0], filename_wsize);
|
::MultiByteToWideChar(CP_UTF8, 0, filename.Begin, (int)filename.length(), &buf[0], filename_wsize);
|
||||||
::MultiByteToWideChar(CP_UTF8, 0, mode.Begin, (int)mode.length(), (wchar_t*)&buf[filename_wsize + 1], mode_wsize);
|
::MultiByteToWideChar(CP_UTF8, 0, mode.Begin, (int)mode.length(), &buf[filename_wsize + 1], mode_wsize);
|
||||||
buf[filename_wsize] = buf[filename_wsize + 1 + mode_wsize] = 0;
|
buf[filename_wsize] = buf[filename_wsize + 1 + mode_wsize] = 0;
|
||||||
return ::_wfopen((const wchar_t*)&buf[0], (const wchar_t*)&buf[filename_wsize + 1]);
|
return ::_wfopen(&buf[0], &buf[filename_wsize + 1]);
|
||||||
#else
|
#else
|
||||||
// ImStrv is not guaranteed to be zero-terminated.
|
// ImStrv is not guaranteed to be zero-terminated.
|
||||||
ImStrv filename_0 = ImStrdup(filename);
|
ImStrv filename_0 = ImStrdup(filename);
|
||||||
|
Loading…
Reference in New Issue
Block a user