0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-18 07:50:57 +01:00

ircd::util: Fix bswap() to not rely on data()/size() et al.

This commit is contained in:
Jason Volk 2018-01-14 17:59:07 -08:00
parent af0c02cc10
commit b2503ba1d0

View file

@ -32,7 +32,8 @@ T &
ircd::util::bswap(T *const &val) ircd::util::bswap(T *const &val)
{ {
assert(val != nullptr); assert(val != nullptr);
std::reverse(data(*val), data(*val) + size(*val)); const auto ptr{reinterpret_cast<uint8_t *>(val)};
std::reverse(ptr, ptr + sizeof(T));
return *val; return *val;
} }
@ -42,6 +43,8 @@ T
ircd::util::bswap(const T &val) ircd::util::bswap(const T &val)
{ {
T ret; T ret;
std::reverse_copy(data(val), data(val) + size(val), data(ret)); const auto valptr{reinterpret_cast<const uint8_t *>(&val)};
const auto retptr{reinterpret_cast<uint8_t *>(&ret)};
std::reverse_copy(valptr, valptr + sizeof(T), retptr);
return ret; return ret;
} }