Kernel: Make Process::procfs_get_pledge_stats OOM-fallible
We can completely avoid the string allocation by using string_view().
This commit is contained in:
parent
7f44e54ad6
commit
0218c62be4
Notes:
sideshowbarker
2024-07-17 18:41:15 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/0218c62be4 Pull-request: https://github.com/SerenityOS/serenity/pull/12564 Reviewed-by: https://github.com/MaxWipfli
1 changed files with 6 additions and 6 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue