From 3da6d2cdded47ab13e07a5228d030280aca8b872 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Thu, 8 Jul 2021 20:33:50 +0300 Subject: [PATCH] WIN_SetErrorFromHRESULT: kill CR/LF that FormatMessage sticks at the end Fixes: https://github.com/libsdl-org/SDL_mixer/issues/320 --- src/core/windows/SDL_windows.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index 22dadd267..e111ec9c1 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -44,8 +44,17 @@ WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr) { TCHAR buffer[1024]; char *message; + TCHAR *p = buffer; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0, buffer, SDL_arraysize(buffer), NULL); + /* kill CR/LF that FormatMessage() sticks at the end */ + while (*p) { + if (*p == '\r') { + *p = 0; + break; + } + ++p; + } message = WIN_StringToUTF8(buffer); SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); SDL_free(message);