diff --git a/ChangeLog b/ChangeLog index e99ab6ca..1c63a035 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-05-24 Tatsuhiro Tsujikawa + + 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 Removed PKG_CONFIG variable in sqlite3.m4, which conflicts the diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc index e3d2df5a..b0b79b69 100644 --- a/src/PeerConnection.cc +++ b/src/PeerConnection.cc @@ -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(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()); } diff --git a/test/DHTRoutingTableSerializerTest.cc b/test/DHTRoutingTableSerializerTest.cc index f4c148a4..338bb4f4 100644 --- a/test/DHTRoutingTableSerializerTest.cc +++ b/test/DHTRoutingTableSerializerTest.cc @@ -70,7 +70,10 @@ void DHTRoutingTableSerializerTest::testSerialize() // time ss.read(buf, 8); - time_t time = ntoh64(*reinterpret_cast(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(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);