fix: -Wunsafe-buffer-usage warnings with argc, argv (#44366)

* refactor: move uv_setup_args() calls to startup

* refactor: call base::CommandLine::Init() before ContentMain()

* feat: add ElectronCommandLine::AsUtf8()

* refactor: call base::CommandLine::Init() before NodeMain()

* refactor: use ElectronCommandLine::AsUtf8() in NodeMain()

* fix: -Wunsafe-buffer-usage warning in ElectronCommandLine::Init()

* chore: add a DCHECK to confirm ElectronCommandLine was initialized before AsUtf8() is called

* chore: const correctness in ElectronCommandLine::Init() args

* chore: add ElectronCommandLine to macOS Electron Helper app

* chore: move argc, argvc setup into electron_library_main on macOS

* chore: revert BUILD.gn changes

* fix: WideToUTF8() call in ElectronCommandLine::AsUtf8()

* build: add uv to the include paths for app/electron_main_linux

* build: add uv to the include paths for app/electron_library_main.mm

* chore: revert unrelated changes

these were intended for another branch
This commit is contained in:
Charles Kerr 2024-10-29 07:23:08 -05:00 committed by GitHub
parent 39b24aed92
commit dffe00b232
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 58 additions and 60 deletions

View file

@ -127,16 +127,15 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
// If we are already a fiber then continue normal execution.
#endif // defined(ARCH_CPU_32_BITS)
struct Arguments {
{
int argc = 0;
RAW_PTR_EXCLUSION wchar_t** argv =
::CommandLineToArgvW(::GetCommandLineW(), &argc);
~Arguments() { LocalFree(argv); }
} arguments;
if (!arguments.argv)
return -1;
wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
if (!argv)
return -1;
base::CommandLine::Init(0, nullptr); // args ignored on Windows
electron::ElectronCommandLine::Init(argc, argv);
LocalFree(argv);
}
#ifdef _DEBUG
// Don't display assert dialog boxes in CI test runs
@ -159,18 +158,12 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
if (run_as_node || !IsEnvSet("ELECTRON_NO_ATTACH_CONSOLE"))
base::RouteStdioToConsole(false);
std::vector<char*> argv(arguments.argc);
std::transform(arguments.argv, arguments.argv + arguments.argc, argv.begin(),
[](auto& a) { return _strdup(base::WideToUTF8(a).c_str()); });
if (run_as_node) {
base::AtExitManager atexit_manager;
base::i18n::InitializeICU();
auto ret = electron::NodeMain(argv.size(), argv.data());
std::ranges::for_each(argv, free);
return ret;
return electron::NodeMain();
}
base::CommandLine::Init(argv.size(), argv.data());
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
@ -235,6 +228,5 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
content::ContentMainParams params(&delegate);
params.instance = instance;
params.sandbox_info = &sandbox_info;
electron::ElectronCommandLine::Init(arguments.argc, arguments.argv);
return content::ContentMain(std::move(params));
}