SDL: null-terminate the message buffer if FormatMessage() fails

From 6872cb12e67fa6159924406b1b3977158ac30612 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 28 Nov 2021 21:10:46 -0800
Subject: [PATCH] null-terminate the message buffer if FormatMessage() fails

---
 src/core/windows/SDL_windows.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c
index a0c789a63c7..434edd06b19 100644
--- a/src/core/windows/SDL_windows.c
+++ b/src/core/windows/SDL_windows.c
@@ -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') {