Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion runtime/shims/xgameruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,11 @@ HRESULT STDMETHODCALLTYPE pls_get_path(void*, size_t path_size, char* path, size
if (!path) return E_POINTER;
const std::string folder = utf8_of(persistent_storage_dir().native());
if (folder.empty()) return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
if (path_size < folder.size() + 1) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
if (path_size < folder.size() + 1) {
// A short buffer is left untouched but learns the size it needs: the path with its NUL, as slot 3 reports.
if (path_used) *path_used = folder.size() + 1;
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
}
std::memcpy(path, folder.c_str(), folder.size() + 1);
if (path_used) *path_used = folder.size() + 1;
return S_OK;
Expand Down
9 changes: 7 additions & 2 deletions runtime/test/xgameruntime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,13 @@ void check_run_time_load() {
char tiny[2] = {'x', 'x'};
used = 99;
check(reinterpret_cast<GetPath>(slot(pls, 4))(pls, 2, tiny, &used) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) &&
used == 0,
"slot 4 refuses a buffer that is too small");
used == size && tiny[0] == 'x' && tiny[1] == 'x',
"slot 4 refuses a buffer that is too small, reports the size it needs and leaves the buffer alone");
check(reinterpret_cast<GetPath>(slot(pls, 4))(pls, size - 1, path.data(), &used) ==
HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && used == size,
"slot 4 reports the size for a buffer one byte short");
check(reinterpret_cast<GetPath>(slot(pls, 4))(pls, 2, tiny, nullptr) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
"slot 4 tolerates a null used pointer on a short buffer");

{
std::ofstream cache_file(folder / L"cache.bin", std::ios::binary);
Expand Down
Loading