From 8514f354744fc57ba8bd5c2149f4cc2a2b8a3c20 Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 30 Aug 2021 20:46:54 -0400 Subject: [PATCH] [common] windebug: handle FormatMessage failure --- common/src/platform/windows/windebug.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/platform/windows/windebug.c b/common/src/platform/windows/windebug.c index c66c1c3b..3a24cdff 100644 --- a/common/src/platform/windows/windebug.c +++ b/common/src/platform/windows/windebug.c @@ -18,13 +18,14 @@ * Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "common/debug.h" #include "common/windebug.h" #include void DebugWinError(const char * file, const unsigned int line, const char * function, const char * desc, HRESULT status) { char *buffer; - FormatMessageA( + if (!FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, status, @@ -32,7 +33,12 @@ void DebugWinError(const char * file, const unsigned int line, const char * func (char*)&buffer, 1024, NULL - ); + )) + { + DEBUG_ERROR("FormatMessage failed with code 0x%08lx", GetLastError()); + fprintf(stderr, "%12" PRId64 " [E] %20s:%-4u | %-30s | %s: 0x%08x\n", microtime(), file, line, function, desc, (int)status); + return; + } for(size_t i = strlen(buffer) - 1; i > 0; --i) if (buffer[i] == '\n' || buffer[i] == '\r')