From 53e60b0dd5aed8cff970faee3bd36b8324f4db49 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 3 Oct 2024 06:00:25 -0700 Subject: [PATCH] Move buffer_ to heap Resolves warning: src\win\path_util.cc(54): warning C6262: Function uses '131804' bytes of stack: exceeds /analyze:stacksize '16384'. Consider moving some data to heap. --- src/win/path_util.cc | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/win/path_util.cc b/src/win/path_util.cc index 9b6b8201d..764c0330c 100644 --- a/src/win/path_util.cc +++ b/src/win/path_util.cc @@ -58,38 +58,37 @@ std::wstring get_shell_path(std::wstring filename) { return shellpath; } - wchar_t buffer_[MAX_ENV]; + wchar_t* buffer_ = new wchar_t[MAX_ENV]; int read = ::GetEnvironmentVariableW(L"Path", buffer_, MAX_ENV); - if (!read) { - return shellpath; - } - - std::wstring delimiter = L";"; - size_t pos = 0; - std::vector paths; - std::wstring buffer(buffer_); - while ((pos = buffer.find(delimiter)) != std::wstring::npos) { - paths.push_back(buffer.substr(0, pos)); - buffer.erase(0, pos + delimiter.length()); - } + if (read) { + std::wstring delimiter = L";"; + size_t pos = 0; + std::vector paths; + std::wstring buffer(buffer_); + while ((pos = buffer.find(delimiter)) != std::wstring::npos) { + paths.push_back(buffer.substr(0, pos)); + buffer.erase(0, pos + delimiter.length()); + } - const wchar_t *filename_ = filename.c_str(); + const wchar_t *filename_ = filename.c_str(); - for (size_t i = 0; i < paths.size(); ++i) { - std::wstring path = paths[i]; - wchar_t searchPath[MAX_PATH]; - ::PathCombineW(searchPath, const_cast(path.c_str()), filename_); + for (size_t i = 0; i < paths.size(); ++i) { + std::wstring path = paths[i]; + wchar_t searchPath[MAX_PATH]; + ::PathCombineW(searchPath, const_cast(path.c_str()), filename_); - if (searchPath == NULL) { - continue; - } + if (searchPath == NULL) { + continue; + } - if (file_exists(searchPath)) { - shellpath = searchPath; - break; + if (file_exists(searchPath)) { + shellpath = searchPath; + break; + } } } + delete[] buffer_; return shellpath; }