Skip to content

Commit 53e60b0

Browse files
committed
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.
1 parent 796e11e commit 53e60b0

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/win/path_util.cc

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,37 @@ std::wstring get_shell_path(std::wstring filename) {
5858
return shellpath;
5959
}
6060

61-
wchar_t buffer_[MAX_ENV];
61+
wchar_t* buffer_ = new wchar_t[MAX_ENV];
6262
int read = ::GetEnvironmentVariableW(L"Path", buffer_, MAX_ENV);
63-
if (!read) {
64-
return shellpath;
65-
}
66-
67-
std::wstring delimiter = L";";
68-
size_t pos = 0;
69-
std::vector<std::wstring> paths;
70-
std::wstring buffer(buffer_);
71-
while ((pos = buffer.find(delimiter)) != std::wstring::npos) {
72-
paths.push_back(buffer.substr(0, pos));
73-
buffer.erase(0, pos + delimiter.length());
74-
}
63+
if (read) {
64+
std::wstring delimiter = L";";
65+
size_t pos = 0;
66+
std::vector<std::wstring> paths;
67+
std::wstring buffer(buffer_);
68+
while ((pos = buffer.find(delimiter)) != std::wstring::npos) {
69+
paths.push_back(buffer.substr(0, pos));
70+
buffer.erase(0, pos + delimiter.length());
71+
}
7572

76-
const wchar_t *filename_ = filename.c_str();
73+
const wchar_t *filename_ = filename.c_str();
7774

78-
for (size_t i = 0; i < paths.size(); ++i) {
79-
std::wstring path = paths[i];
80-
wchar_t searchPath[MAX_PATH];
81-
::PathCombineW(searchPath, const_cast<wchar_t*>(path.c_str()), filename_);
75+
for (size_t i = 0; i < paths.size(); ++i) {
76+
std::wstring path = paths[i];
77+
wchar_t searchPath[MAX_PATH];
78+
::PathCombineW(searchPath, const_cast<wchar_t*>(path.c_str()), filename_);
8279

83-
if (searchPath == NULL) {
84-
continue;
85-
}
80+
if (searchPath == NULL) {
81+
continue;
82+
}
8683

87-
if (file_exists(searchPath)) {
88-
shellpath = searchPath;
89-
break;
84+
if (file_exists(searchPath)) {
85+
shellpath = searchPath;
86+
break;
87+
}
9088
}
9189
}
9290

91+
delete[] buffer_;
9392
return shellpath;
9493
}
9594

0 commit comments

Comments
 (0)