Skip to content

Commit bc7ac13

Browse files
pmttavaraicculus
authored andcommitted
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.
1 parent db5cd8c commit bc7ac13

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/filesystem/windows/SDL_sysfilesystem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ SDL_GetBasePath(void)
6868
path = (WCHAR *) ptr;
6969

7070
len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen);
71-
if (len != buflen) {
71+
/* if it truncated, then len >= buflen - 1 */
72+
/* if there was enough room (or failure), len < buflen - 1 */
73+
if (len < buflen - 1) {
7274
break;
7375
}
7476

0 commit comments

Comments
 (0)