Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions errnfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@ static void errw(const wchar_t* s) {

static void vfmt_to(HANDLE h, bool is_console, const wchar_t* fmt, va_list ap) {
wchar_t stackbuf[2048];
va_list ap2;
va_copy(ap2, ap);
#if defined(_MSC_VER)
int n = _vsnwprintf_s(stackbuf, _countof(stackbuf), _TRUNCATE, fmt, ap);
int n = _vsnwprintf_s(stackbuf, _countof(stackbuf), _TRUNCATE, fmt, ap2);
#else
int n = vswprintf(stackbuf, (int)(sizeof(stackbuf) / sizeof(stackbuf[0])), fmt, ap);
int n = vswprintf(stackbuf, (int)(sizeof(stackbuf) / sizeof(stackbuf[0])), fmt, ap2);
#endif
va_end(ap2);
if (n >= 0) {
write_w(h, is_console, stackbuf);
return;
Expand All @@ -158,7 +161,6 @@ static void vfmt_to(HANDLE h, bool is_console, const wchar_t* fmt, va_list ap) {
wchar_t* dyn = (wchar_t*)malloc(cap * sizeof(wchar_t));
if (!dyn) return;

va_list ap2;
va_copy(ap2, ap);
#if defined(_MSC_VER)
_vsnwprintf_s(dyn, cap, _TRUNCATE, fmt, ap2);
Expand Down
9 changes: 7 additions & 2 deletions modsnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ static void errw(const wchar_t* s) {

static void vfmt_to(HANDLE h, bool is_console, const wchar_t* fmt, va_list ap) {
wchar_t stackbuf[2048];
int n = _vsnwprintf_s(stackbuf, _countof(stackbuf), _TRUNCATE, fmt, ap);
va_list copy;
va_copy(copy, ap);
int n = _vsnwprintf_s(stackbuf, _countof(stackbuf), _TRUNCATE, fmt, copy);
va_end(copy);
if (n >= 0) {
write_w(h, is_console, stackbuf);
return;
Expand All @@ -103,7 +106,9 @@ static void vfmt_to(HANDLE h, bool is_console, const wchar_t* fmt, va_list ap) {
wchar_t* dyn = (wchar_t*)malloc(cap * sizeof(wchar_t));
if (!dyn) return;

_vsnwprintf_s(dyn, cap, _TRUNCATE, fmt, ap);
va_copy(copy, ap);
_vsnwprintf_s(dyn, cap, _TRUNCATE, fmt, copy);
va_end(copy);
write_w(h, is_console, dyn);
free(dyn);
}
Expand Down
9 changes: 7 additions & 2 deletions wchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ static void errw(const wchar_t* s) {

static void vfmt_to(HANDLE h, bool is_console, const wchar_t* fmt, va_list ap) {
wchar_t stackbuf[2048];
int n = _vsnwprintf_s(stackbuf, _countof(stackbuf), _TRUNCATE, fmt, ap);
va_list copy;
va_copy(copy, ap);
int n = _vsnwprintf_s(stackbuf, _countof(stackbuf), _TRUNCATE, fmt, copy);
va_end(copy);
if (n >= 0) {
write_w(h, is_console, stackbuf);
return;
Expand All @@ -154,7 +157,9 @@ static void vfmt_to(HANDLE h, bool is_console, const wchar_t* fmt, va_list ap) {
wchar_t* dyn = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, cap * sizeof(wchar_t));
if (!dyn) return;

_vsnwprintf_s(dyn, cap, _TRUNCATE, fmt, ap);
va_copy(copy, ap);
_vsnwprintf_s(dyn, cap, _TRUNCATE, fmt, copy);
va_end(copy);
write_w(h, is_console, dyn);
HeapFree(GetProcessHeap(), 0, dyn);
}
Expand Down