Fix out-of-range exception in parsing Dwarf5 on s390x

This commit is contained in:
HarryLeeIBM 2024-06-20 07:55:53 -07:00
parent 9a55cdf77c
commit 216b9a7a00

View File

@ -202,7 +202,10 @@ uint64_t readU64(std::string_view & sp)
{
SAFE_CHECK(sp.size() >= N, "underflow");
uint64_t x = 0;
memcpy(&x, sp.data(), N);
if constexpr (std::endian::native == std::endian::little)
memcpy(&x, sp.data(), N);
else
memcpy(reinterpret_cast<char*>(&x) + sizeof(uint64_t) - N, sp.data(), N);
sp.remove_prefix(N);
return x;
}