[common] windebug: handle FormatMessage failure

This commit is contained in:
Quantum 2021-08-30 20:46:54 -04:00 committed by Geoffrey McRae
parent e05bb196f0
commit 8514f35474

View file

@ -18,13 +18,14 @@
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "common/debug.h"
#include "common/windebug.h"
#include <stdio.h>
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')