Fix heinous TMemoryBuffer bug and warning in FileTransport
authorMark Slee <mcslee@apache.org>
Thu, 22 Mar 2007 02:35:33 +0000 (02:35 +0000)
committerMark Slee <mcslee@apache.org>
Thu, 22 Mar 2007 02:35:33 +0000 (02:35 +0000)
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
lib/cpp/src/transport/TTransportUtils.cpp

index edba17e..9a3ca30 100644 (file)
@@ -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);
index b564982..aaefb2c 100644 (file)
@@ -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.");
     }
   }