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 edba17e..9a3ca30 100644
--- a/lib/cpp/src/transport/TFileTransport.cpp
+++ b/lib/cpp/src/transport/TFileTransport.cpp
@@ -596,7 +596,7 @@
       // 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 b564982..aaefb2c 100644
--- a/lib/cpp/src/transport/TTransportUtils.cpp
+++ b/lib/cpp/src/transport/TTransportUtils.cpp
@@ -214,10 +214,11 @@
     }
     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.");
     }
   }