From 548585cccc7ecaa0c7bc92aa0fb4a1b553bad49f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 15 Nov 2009 11:20:55 +0000 Subject: [PATCH] 2009-11-15 Tatsuhiro Tsujikawa Applied a patch from tizianomueller to fix sigbus errors on Linux sparc. I modified the patch to eliminate a cast to uint32_t* and include file ordering. * src/PeerListProcessor.h * src/bittorrent_helper.cc --- ChangeLog | 8 ++++++++ src/PeerListProcessor.h | 9 +++++++-- src/bittorrent_helper.cc | 13 +++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20fde92c..0552cdbe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-11-15 Tatsuhiro Tsujikawa + + Applied a patch from tizianomueller to fix sigbus errors on Linux + sparc. I modified the patch to eliminate a cast to uint32_t* and + include file ordering. + * src/PeerListProcessor.h + * src/bittorrent_helper.cc + 2009-11-13 Tatsuhiro Tsujikawa Added util::parseUIntNoThrow(). Use it in Request::parseUrl(). diff --git a/src/PeerListProcessor.h b/src/PeerListProcessor.h index 04d79c4a..d96aa2be 100644 --- a/src/PeerListProcessor.h +++ b/src/PeerListProcessor.h @@ -36,6 +36,9 @@ #define _D_PEER_LIST_PROCESSOR_H_ #include "common.h" + +#include + #include "a2netcompat.h" #include "bencode.h" #include "Peer.h" @@ -83,9 +86,11 @@ public: if(length%6 == 0) { for(size_t i = 0; i < length; i += 6) { struct in_addr in; - in.s_addr = *(uint32_t*)(peerData.s().c_str()+i); + memcpy(&in.s_addr, peerData.s().c_str()+i, sizeof(uint32_t)); std::string ipaddr = inet_ntoa(in); - uint16_t port = ntohs(*(uint16_t*)(peerData.s().c_str()+i+4)); + uint16_t port_nworder; + memcpy(&port_nworder, peerData.s().c_str()+i+4, sizeof(uint16_t)); + uint16_t port = ntohs(port_nworder); *dest = SharedHandle(new Peer(ipaddr, port)); ++dest; } diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index 60bc11bc..8d0131a4 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -773,10 +773,9 @@ bool createcompact return false; } struct sockaddr_in* in = reinterpret_cast(res->ai_addr); - uint32_t* addrp = (uint32_t*)compact; - *addrp = in->sin_addr.s_addr; - uint16_t* portp = (uint16_t*)(compact+4); - *portp = htons(port); + memcpy(compact, &(in->sin_addr.s_addr), sizeof(uint32_t)); + uint16_t port_nworder(htons(port)); + memcpy(compact+4, &port_nworder, sizeof(uint16_t)); freeaddrinfo(res); return true; } @@ -790,7 +789,7 @@ std::pair unpackcompact(const unsigned char* compact) in.sin_len = sizeof(in); #endif // HAVE_SOCKADDR_IN_SIN_LEN in.sin_family = AF_INET; - in.sin_addr.s_addr = *reinterpret_cast(compact); + memcpy(&(in.sin_addr.s_addr), compact, sizeof(uint32_t)); in.sin_port = 0; char host[NI_MAXHOST]; int s; @@ -800,7 +799,9 @@ std::pair unpackcompact(const unsigned char* compact) if(s) { return std::pair(); } - uint16_t port = ntohs(*(uint16_t*)(compact+sizeof(uint32_t))); + uint16_t port_nworder; + memcpy(&port_nworder, compact+sizeof(uint32_t), sizeof(uint16_t)); + uint16_t port = ntohs(port_nworder); return std::pair(host, port); }