فهرست منبع

2009-11-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	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
Tatsuhiro Tsujikawa 16 سال پیش
والد
کامیت
548585cccc
3فایلهای تغییر یافته به همراه22 افزوده شده و 8 حذف شده
  1. 8 0
      ChangeLog
  2. 7 2
      src/PeerListProcessor.h
  3. 7 6
      src/bittorrent_helper.cc

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2009-11-15  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	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  <t-tujikawa@users.sourceforge.net>
 
 	Added util::parseUIntNoThrow(). Use it in Request::parseUrl().

+ 7 - 2
src/PeerListProcessor.h

@@ -36,6 +36,9 @@
 #define _D_PEER_LIST_PROCESSOR_H_
 
 #include "common.h"
+
+#include <cstring>
+
 #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<Peer>(new Peer(ipaddr, port));
 	++dest;
       }

+ 7 - 6
src/bittorrent_helper.cc

@@ -773,10 +773,9 @@ bool createcompact
     return false;
   }
   struct sockaddr_in* in = reinterpret_cast<struct sockaddr_in*>(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<std::string, uint16_t> 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<const uint32_t*>(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<std::string, uint16_t> unpackcompact(const unsigned char* compact)
   if(s) {
     return std::pair<std::string, uint16_t>();
   }
-  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<std::string, uint16_t>(host, port);
 }