summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-02-15 20:56:51 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-16 22:21:37 +0100
commit0218c62be4320c61e006c2b7c68deb1489171764 (patch)
tree9434df47b75f6660d8e30221a9a254a15ddc99c4 /Kernel
parent7f44e54ad6b898923f3b602e311c3dac404533ad (diff)
downloadserenity-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.cpp12
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();