null-terminate the message buffer if FormatMessage() fails

This commit is contained in:
Sam Lantinga 2021-11-28 21:10:46 -08:00
parent b5d47aa297
commit 6872cb12e6
1 changed files with 2 additions and 1 deletions

View File

@ -45,8 +45,9 @@ WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
TCHAR buffer[1024];
char *message;
TCHAR *p = buffer;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0,
DWORD c = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0,
buffer, SDL_arraysize(buffer), NULL);
buffer[c] = 0;
/* kill CR/LF that FormatMessage() sticks at the end */
while (*p) {
if (*p == '\r') {