GH-1997 fix off by one error in 8.3 path logic

This commit is contained in:
Petr Mrázek 2017-09-27 04:28:21 +02:00
parent d276da1359
commit 79d208795c

View File

@ -36,8 +36,13 @@ QString shortPathName(const QString & file)
auto input = file.toStdWString();
std::wstring output;
long length = GetShortPathNameW(input.c_str(), NULL, 0);
// NOTE: this resizing might seem weird...
// when GetShortPathNameW fails, it returns length including null character
// when it succeeds, it returns length excluding null character
// See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364989(v=vs.85).aspx
output.resize(length);
GetShortPathNameW(input.c_str(),(LPWSTR)output.c_str(),length);
output.resize(length-1);
QString ret = QString::fromStdWString(output);
return ret;
}