From 26a14c51753a0c4ff02e952fcae3eceed3e78105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 12 Sep 2024 00:04:49 +0200 Subject: [PATCH] [util] Fix GetEnvironmentVariableW usage --- src/util/util_env.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/util_env.cpp b/src/util/util_env.cpp index 8441b25b..c86c3abf 100644 --- a/src/util/util_env.cpp +++ b/src/util/util_env.cpp @@ -24,7 +24,9 @@ namespace dxvk::env { result.resize(MAX_PATH + 1); DWORD len = ::GetEnvironmentVariableW(str::tows(name).c_str(), result.data(), MAX_PATH); - result.resize(len); + if (!len || len >= MAX_PATH) + return ""; + result.resize(len + 1); return str::fromws(result.data()); #else @@ -80,7 +82,9 @@ namespace dxvk::env { exePath.resize(MAX_PATH + 1); DWORD len = ::GetModuleFileNameW(NULL, exePath.data(), MAX_PATH); - exePath.resize(len); + if (!len || len == MAX_PATH) + return ""; + exePath.resize(len + 1); return str::fromws(exePath.data()); #elif defined(__linux__)