Commit bb22b100 authored by Andreas Schwab's avatar Andreas Schwab

Do proper endian conversions

This fixes all testsuite failures on big endian hosts.
parent e326df21
...@@ -1853,7 +1853,7 @@ class binary_reader ...@@ -1853,7 +1853,7 @@ class binary_reader
} }
// reverse byte order prior to conversion if necessary // reverse byte order prior to conversion if necessary
if (is_little_endian && !InputIsLittleEndian) if (is_little_endian != InputIsLittleEndian)
{ {
vec[sizeof(NumberType) - i - 1] = static_cast<uint8_t>(current); vec[sizeof(NumberType) - i - 1] = static_cast<uint8_t>(current);
} }
......
...@@ -1278,7 +1278,7 @@ class binary_writer ...@@ -1278,7 +1278,7 @@ class binary_writer
std::memcpy(vec.data(), &n, sizeof(NumberType)); std::memcpy(vec.data(), &n, sizeof(NumberType));
// step 2: write array to output (with possible reordering) // step 2: write array to output (with possible reordering)
if (is_little_endian and not OutputIsLittleEndian) if (is_little_endian != OutputIsLittleEndian)
{ {
// reverse byte order prior to conversion if necessary // reverse byte order prior to conversion if necessary
std::reverse(vec.begin(), vec.end()); std::reverse(vec.begin(), vec.end());
......
...@@ -8333,7 +8333,7 @@ class binary_reader ...@@ -8333,7 +8333,7 @@ class binary_reader
} }
// reverse byte order prior to conversion if necessary // reverse byte order prior to conversion if necessary
if (is_little_endian && !InputIsLittleEndian) if (is_little_endian != InputIsLittleEndian)
{ {
vec[sizeof(NumberType) - i - 1] = static_cast<uint8_t>(current); vec[sizeof(NumberType) - i - 1] = static_cast<uint8_t>(current);
} }
...@@ -9746,7 +9746,7 @@ class binary_writer ...@@ -9746,7 +9746,7 @@ class binary_writer
std::memcpy(vec.data(), &n, sizeof(NumberType)); std::memcpy(vec.data(), &n, sizeof(NumberType));
// step 2: write array to output (with possible reordering) // step 2: write array to output (with possible reordering)
if (is_little_endian and not OutputIsLittleEndian) if (is_little_endian != OutputIsLittleEndian)
{ {
// reverse byte order prior to conversion if necessary // reverse byte order prior to conversion if necessary
std::reverse(vec.begin(), vec.end()); std::reverse(vec.begin(), vec.end());
......
...@@ -599,9 +599,8 @@ struct pod_serializer ...@@ -599,9 +599,8 @@ struct pod_serializer
static void to_json(BasicJsonType& j, const T& t) noexcept static void to_json(BasicJsonType& j, const T& t) noexcept
{ {
auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t)); auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
std::uint64_t value = bytes[0]; std::uint64_t value;
for (auto i = 1; i < 8; ++i) std::memcpy(&value, bytes, sizeof(value));
value |= std::uint64_t{bytes[i]} << 8 * i;
nlohmann::to_json(j, value); nlohmann::to_json(j, value);
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment