Thrift: TMemoryBuffer now handles NULLs again.

Summary:
Boz is using TMemoryBuffer by constructing it will a NULL buffer,
then doing a resetBuffer later.  This patch re-enables that.

Blame Rev: 55988

Reviewed By: aditya

Test Plan:
Thrift compiles.
Will test feed after this is comitted.

Revert Plan: ok


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665216 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TTransportUtils.cpp b/lib/cpp/src/transport/TTransportUtils.cpp
index e5523be..4ca1083 100644
--- a/lib/cpp/src/transport/TTransportUtils.cpp
+++ b/lib/cpp/src/transport/TTransportUtils.cpp
@@ -204,6 +204,11 @@
 }
 
 uint32_t TMemoryBuffer::readAppendToString(std::string& str, uint32_t len) {
+  // Don't get some stupid assertion failure.
+  if (buffer_ == NULL) {
+    return 0;
+  }
+
   // Check avaible data for reading
   uint32_t avail = wPos_ - rPos_;
   if (avail == 0) {
diff --git a/lib/cpp/src/transport/TTransportUtils.h b/lib/cpp/src/transport/TTransportUtils.h
index 3e903fd..9499acd 100644
--- a/lib/cpp/src/transport/TTransportUtils.h
+++ b/lib/cpp/src/transport/TTransportUtils.h
@@ -246,7 +246,7 @@
 
   // Common initialization done by all constructors.
   void initCommon(uint8_t* buf, uint32_t size, bool owner, uint32_t wPos) {
-    if (buf == NULL) {
+    if (buf == NULL && size != 0) {
       assert(owner);
       buf = (uint8_t*)malloc(size);
       if (buf == NULL) {
@@ -316,10 +316,16 @@
   }
 
   std::string getBufferAsString() {
+    if (buffer_ == NULL) {
+      return "";
+    }
     return std::string((char*)buffer_, (std::string::size_type)bufferSize_);
   }
 
   void appendBufferToString(std::string& str) {
+    if (buffer_ == NULL) {
+      return;
+    }
     str.append((char*)buffer_, bufferSize_);
   }