From 8e643b9b5f24d4cac68d59b1e2be9d161fb75974 Mon Sep 17 00:00:00 2001 From: Brad King <brad.king@kitware.com> Date: Wed, 24 Aug 2016 10:40:35 -0400 Subject: [PATCH] SystemTools: Fix crash in GetShortPath When `GetShortPathNameW` returns a 0 buffer size then we should not call it again. Change-Id: I6529013ec3c792796649c25168f6c67b60ac7238 --- SystemTools.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index eb2bec6..1a73b16 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -4725,8 +4725,11 @@ bool SystemTools::GetShortPath(const std::string& path, std::string& shortPath) std::wstring wtempPath = Encoding::ToWide(tempPath); DWORD ret = GetShortPathNameW(wtempPath.c_str(), NULL, 0); std::vector<wchar_t> buffer(ret); - ret = GetShortPathNameW(wtempPath.c_str(), - &buffer[0], static_cast<DWORD>(buffer.size())); + if (ret != 0) + { + ret = GetShortPathNameW(wtempPath.c_str(), + &buffer[0], static_cast<DWORD>(buffer.size())); + } if (ret == 0) { -- GitLab