Bug 1121970 - Debug output from printf_stderr gets clipped on Windows. r=nfroyd

This commit is contained in:
Jim Mathies 2015-01-20 08:18:26 -06:00
parent fcb5c81512
commit 60cb268efa

View File

@ -17,6 +17,7 @@
#ifdef XP_WIN
#include <io.h>
#include <windows.h>
#include "mozilla/UniquePtr.h"
#endif
#ifdef ANDROID
@ -24,6 +25,8 @@
#include <unistd.h>
#endif
using namespace mozilla;
const char*
NS_strspnp(const char* aDelims, const char* aStr)
{
@ -338,13 +341,19 @@ vprintf_stderr(const char* aFmt, va_list aArgs)
}
if (IsDebuggerPresent()) {
char buf[2048];
va_list argsCpy;
VARARGS_ASSIGN(argsCpy, aArgs);
vsnprintf(buf, sizeof(buf), aFmt, argsCpy);
buf[sizeof(buf) - 1] = '\0';
va_end(argsCpy);
OutputDebugStringA(buf);
int lengthNeeded = _vscprintf(aFmt, aArgs);
if (lengthNeeded) {
lengthNeeded++;
auto buf = MakeUnique<char[]>(lengthNeeded);
if (buf) {
va_list argsCpy;
VARARGS_ASSIGN(argsCpy, aArgs);
vsnprintf(buf.get(), lengthNeeded, aFmt, argsCpy);
buf[lengthNeeded - 1] = '\0';
va_end(argsCpy);
OutputDebugStringA(buf.get());
}
}
}
FILE* fp = _fdopen(_dup(2), "a");