Skip to content

Commit 02379e2

Browse files
committed
Fix #1973
1 parent 15ba61b commit 02379e2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

httplib.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,8 +2910,16 @@ inline bool mmap::open(const char *path) {
29102910

29112911
#if defined(_WIN32)
29122912
std::wstring wpath;
2913-
for (size_t i = 0; i < strlen(path); i++) {
2914-
wpath += path[i];
2913+
{
2914+
auto len = static_cast<int>(strlen(path));
2915+
2916+
auto wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, nullptr, 0);
2917+
if (wlen <= 0) { return false; }
2918+
wpath.resize(wlen);
2919+
2920+
auto pwpath = reinterpret_cast<LPWSTR>(wpath.data());
2921+
wlen = ::MultiByteToWideChar(CP_UTF8, 0, path, len, pwpath, wlen);
2922+
if (wlen != wpath.size()) { return false; }
29152923
}
29162924

29172925
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8

0 commit comments

Comments
 (0)