diff options
author | Nico Weber <thakis@chromium.org> | 2023-02-10 20:53:39 -0500 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-02-12 22:54:28 +0100 |
commit | 9cfd7a299c42136fe56b4e1c30e46705401fc90b (patch) | |
tree | 3b190bf01d67ff940c90a36e0580a07097dbe357 | |
parent | f698585097fcc1cd2770483dcfea774279c5a770 (diff) | |
download | serenity-9cfd7a299c42136fe56b4e1c30e46705401fc90b.zip |
Userland: Use allocation-failure safe functions where it's easy
I went through all callers of adopt_own() and replaced them with
try_make<>() if possible or adopt_nonnull_own_or_enomem() else
in cases where it was easy (i.e. in functions already returning
ErrorOr).
No intended behavior change.
-rw-r--r-- | Userland/DevTools/HackStudio/ProjectConfig.cpp | 2 | ||||
-rw-r--r-- | Userland/DevTools/Profiler/Profile.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibGLSL/Compiler.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGLSL/Linker.cpp | 2 |
4 files changed, 7 insertions, 7 deletions
diff --git a/Userland/DevTools/HackStudio/ProjectConfig.cpp b/Userland/DevTools/HackStudio/ProjectConfig.cpp index e44b1c7419..2171c03b21 100644 --- a/Userland/DevTools/HackStudio/ProjectConfig.cpp +++ b/Userland/DevTools/HackStudio/ProjectConfig.cpp @@ -24,7 +24,7 @@ ErrorOr<NonnullOwnPtr<ProjectConfig>> ProjectConfig::try_load_project_config(Dep if (!json.is_object()) return Error::from_string_literal("The topmost JSON element is not an object"); - return adopt_own(*new ProjectConfig(json.as_object())); + return try_make<ProjectConfig>(json.as_object()); } NonnullOwnPtr<ProjectConfig> ProjectConfig::create_empty() diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 5d76703452..2247fbf1b7 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -334,13 +334,13 @@ ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path .executable = executable, }; - auto sampled_process = adopt_own(*new Process { + auto sampled_process = TRY(adopt_nonnull_own_or_enomem(new (nothrow) Process { .pid = event.pid, .executable = executable, .basename = LexicalPath::basename(executable), .start_valid = event.serial, .end_valid = {}, - }); + })); current_processes.set(sampled_process->pid, sampled_process); all_processes.append(move(sampled_process)); @@ -356,13 +356,13 @@ ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path current_processes.remove(event.pid); - auto sampled_process = adopt_own(*new Process { + auto sampled_process = TRY(adopt_nonnull_own_or_enomem(new (nothrow) Process { .pid = event.pid, .executable = executable, .basename = LexicalPath::basename(executable), .start_valid = event.serial, .end_valid = {}, - }); + })); current_processes.set(sampled_process->pid, sampled_process); all_processes.append(move(sampled_process)); diff --git a/Userland/Libraries/LibGLSL/Compiler.cpp b/Userland/Libraries/LibGLSL/Compiler.cpp index 072c6ad5ee..def3d7fe61 100644 --- a/Userland/Libraries/LibGLSL/Compiler.cpp +++ b/Userland/Libraries/LibGLSL/Compiler.cpp @@ -12,7 +12,7 @@ ErrorOr<NonnullOwnPtr<ObjectFile>> Compiler::compile(Vector<String> const&) { // FIXME: implement this function m_messages = {}; - return adopt_own(*new ObjectFile()); + return try_make<ObjectFile>(); } } diff --git a/Userland/Libraries/LibGLSL/Linker.cpp b/Userland/Libraries/LibGLSL/Linker.cpp index 2cc1ba83ee..50e7790a89 100644 --- a/Userland/Libraries/LibGLSL/Linker.cpp +++ b/Userland/Libraries/LibGLSL/Linker.cpp @@ -26,7 +26,7 @@ ErrorOr<NonnullOwnPtr<LinkedShader>> Linker::link(Vector<ObjectFile const*> cons }; TRY(shader.instructions.try_append(instruction)); - return adopt_own(*new LinkedShader(shader)); + return try_make<LinkedShader>(shader); } } |