Improve check for paths requiring extended length form to be used

Documentation claims that paths up to MAX_PATH should work, but actually
paths of significantly shorter length may not work.
This commit is contained in:
Vadim Zeitlin
2025-01-18 15:39:52 +01:00
parent a6d20e5c73
commit 5ed4dffd24
+10 -3
View File
@@ -2219,9 +2219,16 @@ wxString wxFileName::GetPath( int flags, wxPathFormat format ) const
fnAbs.MakeAbsolute();
const wxString absPath = fnAbs.DoGetPath(flags, format);
// No need to do anything if it fits. Note that the exact inequality is
// important here, paths of exactly MAX_PATH length don't work.
if ( absPath.length() < MAX_PATH )
// No need to do anything if it fits: note that normally paths up to
// MAX_PATH should work but in practice the limit is lower than that
// depending on whether it's a file or a directory, whether it's in the
// root directory or a subdirectory, Windows version and probably the
// phase of the moon as well, so keep things simple and use the lowest
// known limit which is 248 (which is MAX_PATH minus 12, where 12 is,
// apparently, the length of a 8.3 filename) characters for a directory:
// it does no real harm to use extended length limit paths for shorter
// paths while not using them would result in a "file not found" error.
if ( absPath.length() < 248 )
return fullpath;
// But if it doesn't, we have to switch to using absolute path and