From be0ae5b1be0dcd1272a351bfb9c21d6466a62240 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Thu, 22 Mar 2007 02:35:33 +0000 Subject: [PATCH] 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 --- lib/cpp/src/transport/TFileTransport.cpp | 2 +- lib/cpp/src/transport/TTransportUtils.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) 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."); } } -- 2.17.1