Skip to content

Commit 84ed966

Browse files
committed
[FIX] : fix for _MSC_VER : Use Windows secure crt functions
1 parent c5d8f8c commit 84ed966

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,20 @@ namespace IGFD
412412
std::wstring ret;
413413
if (!str.empty())
414414
{
415-
size_t sz = std::mbstowcs(nullptr, str.c_str(), str.size());
415+
size_t sz = 0U;
416+
#ifndef _MSC_VER
417+
sz = std::mbstowcs(nullptr, str.c_str(), str.size());
418+
#else // _MSC_VER
419+
mbstowcs_s(&sz, nullptr, 0, str.c_str(), str.size());
420+
#endif // _MSC_VER
416421
if (sz)
417422
{
418423
ret.resize(sz);
424+
#ifndef _MSC_VER
419425
std::mbstowcs((wchar_t*)ret.data(), str.c_str(), sz);
426+
#else // _MSC_VER
427+
mbstowcs_s(nullptr, ret.data(), sz, str.c_str(), sz);
428+
#endif // _MSC_VER
420429
}
421430
}
422431
return ret;
@@ -427,11 +436,20 @@ namespace IGFD
427436
std::string ret;
428437
if (!str.empty())
429438
{
430-
size_t sz = std::wcstombs(nullptr, str.c_str(), str.size());
439+
size_t sz = 0U;
440+
#ifndef _MSC_VER
441+
sz = std::wcstombs(nullptr, str.c_str(), str.size());
442+
#else // _MSC_VER
443+
wcstombs_s(&sz, nullptr, 0, str.c_str(), str.size());
444+
#endif // _MSC_VER
431445
if (sz)
432446
{
433447
ret.resize(sz);
434-
std::wcstombs((char*)ret.data(), str.c_str(), sz);
448+
#ifndef _MSC_VER
449+
std::wcstombs((wchar_t*)ret.data(), str.c_str(), sz);
450+
#else // _MSC_VER
451+
wcstombs_s(nullptr, ret.data(), sz, str.c_str(), sz);
452+
#endif // _MSC_VER
435453
}
436454
}
437455
return ret;
@@ -482,7 +500,7 @@ namespace IGFD
482500
#define mini(a,b) (((a) < (b)) ? (a) : (b))
483501
const DWORD countChars = mini(GetLogicalDriveStringsA(mydrives, lpBuffer), 2047);
484502
#undef mini
485-
if (countChars > 0)
503+
if (countChars > 0U && countChars < 2049U)
486504
{
487505
std::string var = std::string(lpBuffer, (size_t)countChars);
488506
IGFD::Utils::ReplaceString(var, "\\", "");

0 commit comments

Comments
 (0)