You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2013/06/04 22:25:58 UTC
git commit: THRIFT-1982 vsnprintf on Windows have different semantics
Patch: Konrad Grochowski
Updated Branches:
refs/heads/master f2b094f1f -> d65216df1
THRIFT-1982 vsnprintf on Windows have different semantics
Patch: Konrad Grochowski
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/d65216df
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/d65216df
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/d65216df
Branch: refs/heads/master
Commit: d65216df190b0ff1522098c8a552594ce29feb3d
Parents: f2b094f
Author: Roger Meier <ro...@apache.org>
Authored: Tue Jun 4 22:25:06 2013 +0200
Committer: Roger Meier <ro...@apache.org>
Committed: Tue Jun 4 22:25:06 2013 +0200
----------------------------------------------------------------------
lib/cpp/src/thrift/Thrift.cpp | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/d65216df/lib/cpp/src/thrift/Thrift.cpp
----------------------------------------------------------------------
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 @@ void TOutput::printf(const char *message, ...) {
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 @@ void TOutput::printf(const char *message, ...) {
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;