Patch from Chris Morgan, fixing gcc warnings.

THRIFT-1057: casts in TBinaryProtocol.tcc causing "dereferencing type-punned pointer will break strict-aliasing rules" warnings from gcc



git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1068672 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christian Lavoie 2011-02-08 23:05:47 +00:00
parent 4ebaa761cb
commit 2bbc328212

View File

@ -354,28 +354,34 @@ uint32_t TBinaryProtocolT<Transport_>::readByte(int8_t& byte) {
template <class Transport_> template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::readI16(int16_t& i16) { uint32_t TBinaryProtocolT<Transport_>::readI16(int16_t& i16) {
uint8_t b[2]; union bytes {
this->trans_->readAll(b, 2); uint8_t b[2];
i16 = *(int16_t*)b; int16_t all;
i16 = (int16_t)ntohs(i16); } theBytes;
this->trans_->readAll(theBytes.b, 2);
i16 = (int16_t)ntohs(theBytes.all);
return 2; return 2;
} }
template <class Transport_> template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::readI32(int32_t& i32) { uint32_t TBinaryProtocolT<Transport_>::readI32(int32_t& i32) {
uint8_t b[4]; union bytes {
this->trans_->readAll(b, 4); uint8_t b[4];
i32 = *(int32_t*)b; int32_t all;
i32 = (int32_t)ntohl(i32); } theBytes;
this->trans_->readAll(theBytes.b, 4);
i32 = (int32_t)ntohl(theBytes.all);
return 4; return 4;
} }
template <class Transport_> template <class Transport_>
uint32_t TBinaryProtocolT<Transport_>::readI64(int64_t& i64) { uint32_t TBinaryProtocolT<Transport_>::readI64(int64_t& i64) {
uint8_t b[8]; union bytes {
this->trans_->readAll(b, 8); uint8_t b[8];
i64 = *(int64_t*)b; int64_t all;
i64 = (int64_t)ntohll(i64); } theBytes;
this->trans_->readAll(theBytes.b, 8);
i64 = (int64_t)ntohll(theBytes.all);
return 8; return 8;
} }
@ -384,12 +390,13 @@ uint32_t TBinaryProtocolT<Transport_>::readDouble(double& dub) {
BOOST_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t)); BOOST_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t));
BOOST_STATIC_ASSERT(std::numeric_limits<double>::is_iec559); BOOST_STATIC_ASSERT(std::numeric_limits<double>::is_iec559);
uint64_t bits; union bytes {
uint8_t b[8]; uint8_t b[8];
this->trans_->readAll(b, 8); uint64_t all;
bits = *(uint64_t*)b; } theBytes;
bits = ntohll(bits); this->trans_->readAll(theBytes.b, 8);
dub = bitwise_cast<double>(bits); theBytes.all = ntohll(theBytes.all);
dub = bitwise_cast<double>(theBytes.all);
return 8; return 8;
} }