From: Mark Slee Date: Thu, 22 Mar 2007 02:35:33 +0000 (+0000) Subject: Fix heinous TMemoryBuffer bug and warning in FileTransport X-Git-Tag: 0.2.0~1407 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=be0ae5b1be0dcd1272a351bfb9c21d6466a62240;p=common%2Fthrift.git Fix heinous TMemoryBuffer bug and warning in FileTransport Reviewed By: dweatherford git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665065 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/transport/TFileTransport.cpp b/lib/cpp/src/transport/TFileTransport.cpp index edba17ee..9a3ca302 100644 --- a/lib/cpp/src/transport/TFileTransport.cpp +++ b/lib/cpp/src/transport/TFileTransport.cpp @@ -596,7 +596,7 @@ void TFileTransport::performRecovery() { // point and punt on the error readState_.resetState(readState_.lastDispatchPtr_); char errorMsg[1024]; - sprintf(errorMsg, "TFileTransport: log file corrupted at offset:%llu", + sprintf(errorMsg, "TFileTransport: log file corrupted at offset: %lu", offset_ + readState_.lastDispatchPtr_); perror(errorMsg); throw TTransportException(errorMsg); diff --git a/lib/cpp/src/transport/TTransportUtils.cpp b/lib/cpp/src/transport/TTransportUtils.cpp index b5649826..aaefb2c7 100644 --- a/lib/cpp/src/transport/TTransportUtils.cpp +++ b/lib/cpp/src/transport/TTransportUtils.cpp @@ -214,10 +214,11 @@ void TMemoryBuffer::write(const uint8_t* buf, uint32_t len) { } while (len > avail) { bufferSize_ *= 2; - buffer_ = (uint8_t*)realloc(buffer_, bufferSize_); - if (buffer_ == NULL) { - throw TTransportException("Out of memory."); - } + avail = bufferSize_ - wPos_; + } + buffer_ = (uint8_t*)realloc(buffer_, bufferSize_); + if (buffer_ == NULL) { + throw TTransportException("Out of memory."); } }