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:
parent
39b24aed92
commit
dffe00b232
9 changed files with 58 additions and 60 deletions
|
@ -5,7 +5,8 @@
|
|||
#include "shell/common/electron_command_line.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "uv.h" // NOLINT(build/include_directory)
|
||||
#include "base/containers/to_vector.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
|
||||
namespace electron {
|
||||
|
||||
|
@ -13,17 +14,25 @@ namespace electron {
|
|||
base::CommandLine::StringVector ElectronCommandLine::argv_;
|
||||
|
||||
// static
|
||||
void ElectronCommandLine::Init(int argc, base::CommandLine::CharType** argv) {
|
||||
void ElectronCommandLine::Init(int argc,
|
||||
base::CommandLine::CharType const* const* argv) {
|
||||
DCHECK(argv_.empty());
|
||||
|
||||
// NOTE: uv_setup_args does nothing on Windows, so we don't need to call it.
|
||||
// Otherwise we'd have to convert the arguments from UTF16.
|
||||
#if !BUILDFLAG(IS_WIN)
|
||||
// Hack around with the argv pointer. Used for process.title = "blah"
|
||||
argv = uv_setup_args(argc, argv);
|
||||
#endif
|
||||
// Safety: as is normal in command lines, argc and argv must correspond
|
||||
// to one another. Otherwise there will be out-of-bounds accesses.
|
||||
argv_.assign(argv, UNSAFE_BUFFERS(argv + argc));
|
||||
}
|
||||
|
||||
argv_.assign(argv, argv + argc);
|
||||
// static
|
||||
std::vector<std::string> ElectronCommandLine::AsUtf8() {
|
||||
DCHECK(!argv_.empty());
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
return base::ToVector(
|
||||
argv_, [](const auto& wstr) { return base::WideToUTF8(wstr); });
|
||||
#else
|
||||
return argv_;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue