fix strict aliasing violation

This commit is contained in:
arvidn 2015-10-03 15:13:45 -04:00
parent 82c9efe8fc
commit e59d03f684
2 changed files with 13 additions and 2 deletions

View File

@ -15,6 +15,8 @@ changelog at the end of the file.
#include "libtorrent/sha1.hpp"
#include <boost/detail/endian.hpp> // for BIG_ENDIAN and LITTLE_ENDIAN macros
typedef boost::uint32_t u32;
typedef boost::uint8_t u8;

View File

@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/crc32c.hpp"
#include "libtorrent/ip_voter.hpp"
#include <boost/detail/endian.hpp> // for BIG_ENDIAN and LITTLE_ENDIAN macros
namespace libtorrent
{
namespace {
@ -82,8 +84,15 @@ namespace libtorrent
if (e1.port() > e2.port())
swap(e1, e2);
boost::uint32_t p;
reinterpret_cast<boost::uint16_t*>(&p)[0] = aux::host_to_network(e1.port());
reinterpret_cast<boost::uint16_t*>(&p)[1] = aux::host_to_network(e2.port());
#if defined BOOST_BIG_ENDIAN
p = e1.port() << 16;
p |= e2.port();
#elif defined BOOST_LITTLE_ENDIAN
p = aux::host_to_network(e2.port()) << 16;
p |= aux::host_to_network(e1.port());
#else
#error unsupported endianness
#endif
ret = crc32c_32(p);
}
#if TORRENT_USE_IPV6