THRIFT-1982 vsnprintf on Windows have different semantics
Patch: Konrad Grochowski
diff --git a/lib/cpp/src/thrift/Thrift.cpp b/lib/cpp/src/thrift/Thrift.cpp
index bcbdb1a..6c7f8ae 100644
--- a/lib/cpp/src/thrift/Thrift.cpp
+++ b/lib/cpp/src/thrift/Thrift.cpp
@@ -34,6 +34,19 @@
   char stack_buf[STACK_BUF_SIZE];
   va_list ap;
 
+#ifdef _MSC_VER
+  va_start(ap, message);
+  int need = _vscprintf(message, ap);
+  va_end(ap);
+
+  if (need < STACK_BUF_SIZE) {
+    va_start(ap, message);
+    vsnprintf_s(stack_buf, STACK_BUF_SIZE, _TRUNCATE, message, ap);
+    va_end(ap);
+    f_(stack_buf);
+    return;
+  }
+#else
   va_start(ap, message);
   int need = vsnprintf(stack_buf, STACK_BUF_SIZE, message, ap);
   va_end(ap);
@@ -42,9 +55,15 @@
     f_(stack_buf);
     return;
   }
+#endif
 
   char *heap_buf = (char*)malloc((need+1) * sizeof(char));
   if (heap_buf == NULL) {
+#ifdef _MSC_VER
+    va_start(ap, message);
+    vsnprintf_s(stack_buf, STACK_BUF_SIZE, _TRUNCATE, message, ap);
+    va_end(ap);
+#endif
     // Malloc failed.  We might as well print the stack buffer.
     f_(stack_buf);
     return;