Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug caused by #16592 #16624

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,23 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
}
}

const Remoting::CommandlineArgs eventArgs{ args, cwd, gsl::narrow_cast<uint32_t>(nCmdShow), GetEnvironmentStringsW() };
// GetEnvironmentStringsW() returns a double-null terminated string.
// The hstring(wchar_t*) constructor however only works for regular null-terminated strings.
// Due to that we need to manually search for the terminator.
winrt::hstring env;
{
const wil::unique_environstrings_ptr strings{ GetEnvironmentStringsW() };
const auto beg = strings.get();
auto end = beg;

for (; *end; end += wcsnlen(end, SIZE_T_MAX) + 1)
{
}

env = winrt::hstring{ beg, gsl::narrow<uint32_t>(end - beg) };
}

const Remoting::CommandlineArgs eventArgs{ args, cwd, gsl::narrow_cast<uint32_t>(nCmdShow), std::move(env) };
const auto isolatedMode{ _app.Logic().IsolatedMode() };
const auto result = _manager.ProposeCommandline(eventArgs, isolatedMode);
int exitCode = 0;
Expand Down
Loading