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

@ -9,6 +9,7 @@
#include "base/apple/bundle_locations.h"
#include "base/apple/scoped_nsautorelease_pool.h"
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "content/public/app/content_main.h"
#include "electron/fuses.h"
@ -16,21 +17,22 @@
#include "shell/app/node_main.h"
#include "shell/common/electron_command_line.h"
#include "shell/common/mac/main_application_bundle.h"
#include "uv.h"
int ElectronMain(int argc, char* argv[]) {
electron::ElectronMainDelegate delegate;
content::ContentMainParams params(&delegate);
params.argc = argc;
params.argv = const_cast<const char**>(argv);
argv = uv_setup_args(argc, argv);
base::CommandLine::Init(argc, argv);
electron::ElectronCommandLine::Init(argc, argv);
electron::ElectronMainDelegate delegate;
// Ensure that Bundle Id is set before ContentMain.
// Refs https://chromium-review.googlesource.com/c/chromium/src/+/5581006
delegate.OverrideChildProcessPath();
delegate.OverrideFrameworkBundlePath();
delegate.SetUpBundleOverrides();
return content::ContentMain(std::move(params));
return content::ContentMain(content::ContentMainParams{&delegate});
}
int ElectronInitializeICUandStartNode(int argc, char* argv[]) {
@ -39,6 +41,10 @@ int ElectronInitializeICUandStartNode(int argc, char* argv[]) {
return 1;
}
argv = uv_setup_args(argc, argv);
base::CommandLine::Init(argc, argv);
electron::ElectronCommandLine::Init(argc, argv);
base::AtExitManager atexit_manager;
base::apple::ScopedNSAutoreleasePool pool;
base::apple::SetOverrideFrameworkBundlePath(
@ -47,5 +53,5 @@ int ElectronInitializeICUandStartNode(int argc, char* argv[]) {
.Append("Frameworks")
.Append(ELECTRON_PRODUCT_NAME " Framework.framework"));
base::i18n::InitializeICU();
return electron::NodeMain(argc, argv);
return electron::NodeMain();
}