2009-05-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Fixed g++-4.4 compiler warning: dereferencing type-punned pointer
	will break strict-aliasing rules
	* src/PeerConnection.cc
	* test/DHTRoutingTableSerializerTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-05-23 15:48:20 +00:00
parent 50060985c3
commit a933438401
3 changed files with 18 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2009-05-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed g++-4.4 compiler warning: dereferencing type-punned pointer
will break strict-aliasing rules
* src/PeerConnection.cc
* test/DHTRoutingTableSerializerTest.cc
2009-05-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed PKG_CONFIG variable in sqlite3.m4, which conflicts the

View File

@ -97,7 +97,9 @@ bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength) {
// still 4-lenbufLength bytes to go
return false;
}
uint32_t payloadLength = ntohl(*(reinterpret_cast<uint32_t*>(lenbuf)));
uint32_t payloadLength;
memcpy(&payloadLength, lenbuf, sizeof(payloadLength));
payloadLength = ntohl(payloadLength);
if(payloadLength > MAX_PAYLOAD_LEN) {
throw DL_ABORT_EX(StringFormat(EX_TOO_LONG_PAYLOAD, payloadLength).str());
}

View File

@ -70,7 +70,10 @@ void DHTRoutingTableSerializerTest::testSerialize()
// time
ss.read(buf, 8);
time_t time = ntoh64(*reinterpret_cast<uint64_t*>(buf));
time_t time;
uint64_t timebuf;
memcpy(&timebuf, buf, sizeof(timebuf));
time = ntoh64(timebuf);
std::cerr << time << std::endl;
// localnode
@ -86,7 +89,10 @@ void DHTRoutingTableSerializerTest::testSerialize()
// number of nodes saved
ss.read(buf, 4);
uint32_t numNodes = ntohl(*reinterpret_cast<uint32_t*>(buf));
uint32_t numNodes;
memcpy(&numNodes, buf, sizeof(numNodes));
numNodes = ntohl(numNodes);
CPPUNIT_ASSERT_EQUAL((uint32_t)3, numNodes);
// 4bytes reserved
ss.read(buf, 4);