kernel+libos: Call Vector::try_reserve where it is appropriate
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
70a232cfcd
commit
2abb43d709
@ -49,6 +49,7 @@ Result<u64> ScriptLoader::load(AddressSpace* space)
|
||||
Result<Vector<String>> ScriptLoader::cmdline(const String& path, Vector<String> args)
|
||||
{
|
||||
Vector<String> new_args;
|
||||
TRY(new_args.try_reserve(m_interpreter_cmdline.size() + args.size() + 1));
|
||||
for (auto& arg : m_interpreter_cmdline) { TRY(new_args.try_append(move(arg))); }
|
||||
auto arg = TRY(path.clone());
|
||||
TRY(new_args.try_append(move(arg)));
|
||||
|
@ -17,10 +17,12 @@ Result<u64> sys_poll(Registers*, SyscallArgs args)
|
||||
|
||||
if (!MemoryManager::copy_from_user(fds, kfds, nfds * sizeof(pollfd))) return err(EFAULT);
|
||||
|
||||
Vector<SharedPtr<VFS::Inode>> inodes;
|
||||
auto* current = Scheduler::current();
|
||||
TRY(check_pledge(current, Promise::p_stdio));
|
||||
|
||||
Vector<SharedPtr<VFS::Inode>> inodes;
|
||||
TRY(inodes.try_reserve(nfds));
|
||||
|
||||
for (nfds_t i = 0; i < nfds; i++)
|
||||
{
|
||||
int fd = kfds[i].fd;
|
||||
|
@ -88,6 +88,7 @@ Result<u64> ThreadImage::push_mem_on_stack(const u8* mem, usize size)
|
||||
Result<u64> ThreadImage::push_string_vector_on_stack(const Vector<String>& vec)
|
||||
{
|
||||
Vector<u64> user_vec;
|
||||
TRY(user_vec.try_reserve(vec.size() + 1));
|
||||
for (const auto& item : vec)
|
||||
{
|
||||
// Copy each individual string and retrieve a userspace pointer to said copy
|
||||
|
@ -26,6 +26,7 @@ namespace os
|
||||
Result<void> Process::exec(StringView path, Slice<String> args, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
TRY(argv.try_reserve(args.size() + 1));
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
@ -39,6 +40,7 @@ namespace os
|
||||
Result<void> Process::exec(StringView path, Slice<StringView> args, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
TRY(argv.try_reserve(args.size() + 1));
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
@ -52,10 +54,12 @@ namespace os
|
||||
Result<void> Process::exec(StringView path, Slice<String> args, Slice<String> env, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
TRY(argv.try_reserve(args.size() + 1));
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
Vector<const char*> envp;
|
||||
TRY(envp.try_reserve(env.size() + 1));
|
||||
for (const auto& arg : env) { TRY(envp.try_append(arg.chars())); }
|
||||
TRY(envp.try_append(nullptr));
|
||||
|
||||
@ -83,6 +87,7 @@ namespace os
|
||||
Result<pid_t> Process::spawn(StringView path, Slice<String> args, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
TRY(argv.try_reserve(args.size() + 1));
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
@ -92,6 +97,7 @@ namespace os
|
||||
Result<pid_t> Process::spawn(StringView path, Slice<StringView> args, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
TRY(argv.try_reserve(args.size() + 1));
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
@ -101,10 +107,12 @@ namespace os
|
||||
Result<pid_t> Process::spawn(StringView path, Slice<String> args, Slice<String> env, bool search_in_path)
|
||||
{
|
||||
Vector<const char*> argv;
|
||||
TRY(argv.try_reserve(args.size() + 1));
|
||||
for (const auto& arg : args) { TRY(argv.try_append(arg.chars())); }
|
||||
TRY(argv.try_append(nullptr));
|
||||
|
||||
Vector<const char*> envp;
|
||||
TRY(envp.try_reserve(env.size() + 1));
|
||||
for (const auto& arg : env) { TRY(envp.try_append(arg.chars())); }
|
||||
TRY(envp.try_append(nullptr));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user