From bc7ac134db67392f85ba3dae99c0c191619f4bc0 Mon Sep 17 00:00:00 2001 From: Phillip Trudeau Date: Fri, 11 Jun 2021 09:22:41 +0000 Subject: [PATCH] Windows: Fix SDL_GetBasePath() truncating paths SDL_GetBasePath grows its path buffer for long paths, but GetModuleFileNameExW always truncates and succeeds, so `len` was always equal to (buflen - 1) which is 127. This is easily fixed by checking for (buflen - 1) instead of buflen. For paths longer than MAX_PATH, this problem sometimes got hidden by Windows path shortening ("C:\PROGRA~1\" etc.). Tested on Windows 10 x64 19041 and 10586. --- src/filesystem/windows/SDL_sysfilesystem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c index 5e223d7cc..a2e213212 100644 --- a/src/filesystem/windows/SDL_sysfilesystem.c +++ b/src/filesystem/windows/SDL_sysfilesystem.c @@ -68,7 +68,9 @@ SDL_GetBasePath(void) path = (WCHAR *) ptr; len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen); - if (len != buflen) { + /* if it truncated, then len >= buflen - 1 */ + /* if there was enough room (or failure), len < buflen - 1 */ + if (len < buflen - 1) { break; }