Fix #1007: strcpy requires the number of chars not bytes

This commit is contained in:
Paddy Xu
2021-10-18 21:22:24 +02:00
parent fe6dae67ce
commit e640a8b98a
2 changed files with 3 additions and 3 deletions

View File

@@ -103,7 +103,7 @@ void DOpus::ParseXmlBuffer(PWCHAR buffer)
auto b = new WCHAR[size]; auto b = new WCHAR[size];
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, -1, b, size); MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, -1, b, size);
wcscpy_s(buffer, MAX_PATH_EX, b); // DOpus supports Long Path wcscpy_s(buffer, wcslen(b) + 1, b); // DOpus supports Long Path
delete[] b; delete[] b;
return; // we now cares only the first result return; // we now cares only the first result

View File

@@ -90,14 +90,14 @@ void GetCurrentSelection()
if (hMapFile == nullptr) if (hMapFile == nullptr)
return; return;
auto buffer = static_cast<PWCHAR>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, MAX_PATH * sizeof WCHAR)); auto buffer = static_cast<PWCHAR>(MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, 0));
if (buffer == nullptr) if (buffer == nullptr)
{ {
CloseHandle(hMapFile); CloseHandle(hMapFile);
return; return;
} }
wcscpy_s(buffer, MAX_PATH_EX, dllBuffer); wcscpy_s(buffer, wcslen(dllBuffer) + 1, dllBuffer);
UnmapViewOfFile(buffer); UnmapViewOfFile(buffer);
CloseHandle(hMapFile); CloseHandle(hMapFile);