diff options
| author | Mason Reed <mason@vector35.com> | 2025-04-02 09:00:14 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-04-02 10:27:32 -0400 |
| commit | 3fddd350deb670ede85a59d9213296f1f9618920 (patch) | |
| tree | 5dd14e8d85c7c12c0d02582d4a93b7b4112f1cee /view/sharedcache/core/MappedFileAccessor.cpp | |
| parent | b1445a8de262dfce57784d14547497f6b3ce0463 (diff) | |
[SharedCache] Fix loading entries on linux
Diffstat (limited to 'view/sharedcache/core/MappedFileAccessor.cpp')
| -rw-r--r-- | view/sharedcache/core/MappedFileAccessor.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/view/sharedcache/core/MappedFileAccessor.cpp b/view/sharedcache/core/MappedFileAccessor.cpp index ddd6ce9b..9d6663b5 100644 --- a/view/sharedcache/core/MappedFileAccessor.cpp +++ b/view/sharedcache/core/MappedFileAccessor.cpp @@ -18,15 +18,24 @@ void MappedFileAccessor::WritePointer(size_t address, size_t pointer) *reinterpret_cast<size_t*>(&m_file._mmap[address]) = pointer; } -std::string MappedFileAccessor::ReadNullTermString(size_t address, size_t maxLength) const +std::string MappedFileAccessor::ReadNullTermString(size_t address, const size_t maxLength) const { if (address > Length()) return ""; - auto start = m_file._mmap + address; - auto endLen = (maxLength > 0) ? maxLength : m_file.len; - auto end = start + endLen; - auto nul = std::find(start, end, 0); - return {start, nul}; + // If we are not given a maxLength (i.e. -1) than we will set the max address to the length of the file. + const size_t maxAddr = (maxLength != -1) ? std::min(address + maxLength, Length()) : Length(); + // Read a null-terminated string manually to avoid errors related to string length on Linux. + std::string str; + str.reserve(140); + for (size_t currAddr = address; currAddr < maxAddr; ++currAddr) + { + char c = m_file._mmap[currAddr]; + if (c == '\0') + break; + str += c; + } + str.shrink_to_fit(); + return str; } uint8_t MappedFileAccessor::ReadUInt8(size_t address) |
