From 1734f00d8a534582711df8626140419a7797c2dd Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sun, 12 Feb 2023 15:05:21 +0100 Subject: [PATCH] Don't assume a max length in fs::ShortName --- libaegisub/windows/fs.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libaegisub/windows/fs.cpp b/libaegisub/windows/fs.cpp index f626407e2..fbd28c7fe 100644 --- a/libaegisub/windows/fs.cpp +++ b/libaegisub/windows/fs.cpp @@ -35,7 +35,11 @@ namespace bfs = boost::filesystem; namespace agi { namespace fs { 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()); if (!len) return p.string();