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

@ -27,6 +27,7 @@
#include "shell/app/uv_task_runner.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/api/electron_bindings.h"
#include "shell/common/electron_command_line.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_bindings.h"
#include "shell/common/node_includes.h"
@ -115,12 +116,8 @@ v8::Local<v8::Value> GetParameters(v8::Isolate* isolate) {
namespace electron {
int NodeMain(int argc, char* argv[]) {
bool initialized = base::CommandLine::Init(argc, argv);
if (!initialized) {
LOG(ERROR) << "Failed to initialize CommandLine";
exit(1);
}
int NodeMain() {
DCHECK(base::CommandLine::InitializedForCurrentProcess());
auto os_env = base::Environment::Create();
bool node_options_enabled = electron::fuses::IsNodeOptionsEnabled();
@ -182,11 +179,8 @@ int NodeMain(int argc, char* argv[]) {
// Explicitly register electron's builtin bindings.
NodeBindings::RegisterBuiltinBindings();
// Hack around with the argv pointer. Used for process.title = "blah".
argv = uv_setup_args(argc, argv);
// Parse Node.js cli flags and strip out disallowed options.
std::vector<std::string> args(argv, argv + argc);
const std::vector<std::string> args = ElectronCommandLine::AsUtf8();
ExitIfContainsDisallowedFlags(args);
std::unique_ptr<node::InitializationResult> result =