Skip to content

Commit

Permalink
Move buffer_ to heap
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tyriar committed Oct 3, 2024
1 parent 796e11e commit 53e60b0
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/win/path_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::wstring> 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<std::wstring> 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<wchar_t*>(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<wchar_t*>(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;
}

Expand Down

0 comments on commit 53e60b0

Please sign in to comment.