Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/libehp
1 result
Show changes
Commits on Source (2)
......@@ -20,6 +20,46 @@
// @HEADER_END
#ifdef _WIN32
# include <windows.h>
# undef max
# undef min
# if defined(_MSC_VER)
# define htobe16(x) _byteswap_ushort(x)
# define htole16(x) (x)
# define be16toh(x) _byteswap_ushort(x)
# define le16toh(x) (x)
# define htobe32(x) _byteswap_ulong(x)
# define htole32(x) (x)
# define be32toh(x) _byteswap_ulong(x)
# define le32toh(x) (x)
# define htobe64(x) _byteswap_uint64(x)
# define htole64(x) (x)
# define be64toh(x) _byteswap_uint64(x)
# define le64toh(x) (x)
# elif defined(__GNUC__) || defined(__clang__)
# define htobe16(x) __builtin_bswap16(x)
# define htole16(x) (x)
# define be16toh(x) __builtin_bswap16(x)
# define le16toh(x) (x)
# define htobe32(x) __builtin_bswap32(x)
# define htole32(x) (x)
# define be32toh(x) __builtin_bswap32(x)
# define le32toh(x) (x)
# define htobe64(x) __builtin_bswap64(x)
# define htole64(x) (x)
# define be64toh(x) __builtin_bswap64(x)
# define le64toh(x) (x)
# endif // _MSC_VER
#endif // _WIN32
#include <iostream>
#include <iomanip>
#include <fstream>
......@@ -65,33 +105,36 @@ bool eh_frame_util_t<ptrsize>::read_type(T &value, uint64_t &position, const uin
// set output parameters
position+=sizeof(T);
value=*ptr;
switch(sizeof(T))
switch (sizeof(T))
{
case 1:
break;
case 2:
if(is_be)
value=be16toh(value);
else
value=le16toh(value);
{
const auto in = static_cast<uint16_t>(value);
const auto out = is_be ? be16toh(in) : le16toh(in);
value = static_cast<T>(out);
break;
}
case 4:
if(is_be)
value=be32toh(value);
else
value=le32toh(value);
{
const auto in = static_cast<uint32_t>(value);
const auto out = is_be ? be32toh(in) : le32toh(in);
value = static_cast<T>(out);
break;
}
case 8:
if(is_be)
value=be64toh(value);
else
value=le64toh(value);
{
const auto in = static_cast<uint64_t>(value);
const auto out = is_be ? be64toh(in) : le64toh(in);
value = static_cast<T>(out);
break;
}
default:
throw invalid_argument("Unknown integer size");
}
return false;
}
......