Don't assume a max length in fs::ShortName

This commit is contained in:
arch1t3cht 2023-02-12 15:05:21 +01:00
parent d96fc1f70d
commit 1734f00d8a

View file

@ -35,7 +35,11 @@ namespace bfs = boost::filesystem;
namespace agi { namespace fs { namespace agi { namespace fs {
std::string ShortName(path const& p) { std::string ShortName(path const& p) {
std::wstring out(MAX_PATH + 1, 0); DWORD length = GetShortPathName(p.c_str(), NULL, 0);
if (!length)
return p.string();
std::wstring out(length, 0);
DWORD len = GetShortPathName(p.c_str(), &out[0], out.size()); DWORD len = GetShortPathName(p.c_str(), &out[0], out.size());
if (!len) if (!len)
return p.string(); return p.string();