Skip to content

Commit bd93894

Browse files
authored
Merge pull request #223 from oold/patch-2
Don't pass buffer as format string and free buffer
2 parents a356b90 + d34e460 commit bd93894

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

backward.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,13 +3639,14 @@ template <> class TraceResolverImpl<system_tag::windows_tag>
36393639
char* lpMsgBuf;
36403640
DWORD dw = GetLastError();
36413641

3642-
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3643-
FORMAT_MESSAGE_FROM_SYSTEM |
3644-
FORMAT_MESSAGE_IGNORE_INSERTS,
3645-
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
3646-
(char*)&lpMsgBuf, 0, NULL);
3647-
3648-
printf(lpMsgBuf);
3642+
if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
3643+
FORMAT_MESSAGE_FROM_SYSTEM |
3644+
FORMAT_MESSAGE_IGNORE_INSERTS,
3645+
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
3646+
(char*)&lpMsgBuf, 0, NULL)) {
3647+
std::fprintf(stderr, "%s\n", lpMsgBuf);
3648+
LocalFree(lpMsgBuf);
3649+
}
36493650

36503651
// abort();
36513652
}

0 commit comments

Comments
 (0)