diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-02-15 20:56:51 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-16 22:21:37 +0100 |
commit | 0218c62be4320c61e006c2b7c68deb1489171764 (patch) | |
tree | 9434df47b75f6660d8e30221a9a254a15ddc99c4 /Kernel | |
parent | 7f44e54ad6b898923f3b602e311c3dac404533ad (diff) | |
download | serenity-0218c62be4320c61e006c2b7c68deb1489171764.zip |
Kernel: Make Process::procfs_get_pledge_stats OOM-fallible
We can completely avoid the string allocation by using string_view().
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/ProcessSpecificExposed.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp index fec05d7be1..6189168d7d 100644 --- a/Kernel/ProcessSpecificExposed.cpp +++ b/Kernel/ProcessSpecificExposed.cpp @@ -126,16 +126,16 @@ ErrorOr<NonnullRefPtr<Inode>> Process::lookup_file_descriptions_directory(const ErrorOr<void> Process::procfs_get_pledge_stats(KBufferBuilder& builder) const { JsonObjectSerializer obj { builder }; -#define __ENUMERATE_PLEDGE_PROMISE(x) \ - if (has_promised(Pledge::x)) { \ - if (!builder.is_empty()) \ - builder.append(' '); \ - builder.append(#x); \ +#define __ENUMERATE_PLEDGE_PROMISE(x) \ + if (has_promised(Pledge::x)) { \ + if (!builder.is_empty()) \ + TRY(builder.try_append(' ')); \ + TRY(builder.try_append(#x)); \ } if (has_promises()) { StringBuilder builder; ENUMERATE_PLEDGE_PROMISES - obj.add("promises", builder.build()); + obj.add("promises", builder.string_view()); } #undef __ENUMERATE_PLEDGE_PROMISE obj.finish(); |