================
@@ -623,48 +629,58 @@ static SIZE_T BytesReadableAt(HANDLE process, LPCVOID
addr) {
static std::optional<std::string> ReadRemotePathStringW(HANDLE process,
LPCVOID addr) {
- SIZE_T to_read = std::min<SIZE_T>((MAX_PATH + 1) * sizeof(wchar_t),
- BytesReadableAt(process, addr));
- to_read &= ~SIZE_T(1); // round down to a wchar_t boundary
- if (to_read < sizeof(wchar_t))
- return std::nullopt;
-
- std::array<wchar_t, MAX_PATH + 1> buf{};
- SIZE_T bytes_read = 0;
- if (!::ReadProcessMemory(process, addr, buf.data(), to_read, &bytes_read))
- return std::nullopt;
+ SIZE_T limit = std::min<SIZE_T>(PATHCCH_MAX_CCH * sizeof(wchar_t),
+ BytesReadableAt(process, addr));
+ std::vector<wchar_t> buf;
+ for (SIZE_T capacity = MAX_PATH * sizeof(wchar_t);; capacity *= 2) {
+ SIZE_T to_read = std::min<SIZE_T>(capacity, limit);
+ to_read &= ~SIZE_T(1); // round down to a wchar_t boundary
+ if (to_read < sizeof(wchar_t))
+ return std::nullopt;
- size_t max_chars = bytes_read / sizeof(wchar_t);
- size_t len = ::wcsnlen(buf.data(), max_chars);
- if (len == max_chars) // no null terminator found
- return std::nullopt;
- if (len == 0) // empty string
- return std::nullopt;
+ buf.resize(to_read / sizeof(wchar_t));
+ SIZE_T bytes_read = 0;
+ if (!::ReadProcessMemory(process, addr, buf.data(), to_read, &bytes_read))
+ return std::nullopt;
- std::string result;
- llvm::convertWideToUTF8(std::wstring(buf.data(), len), result);
- return result;
+ size_t max_chars = bytes_read / sizeof(wchar_t);
+ size_t len = ::wcsnlen(buf.data(), max_chars);
+ if (len < max_chars) { // found the null terminator
+ if (len == 0) // empty string
+ return std::nullopt;
+ std::string result;
+ llvm::convertWideToUTF8(std::wstring(buf.data(), len), result);
----------------
charles-zablit wrote:
Fixed, thanks
https://github.com/llvm/llvm-project/pull/206114
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits