1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:07:34 +00:00

Kernel: Make KString factories return KResultOr + use TRY() everywhere

There are a number of places that don't have an error propagation path
right now, so I've added FIXME's about that.
This commit is contained in:
Andreas Kling 2021-09-06 19:24:54 +02:00
parent 69b9b2888c
commit 56a2594de7
21 changed files with 100 additions and 122 deletions

View file

@ -62,7 +62,7 @@ Vector<StringView> parts(StringView const& path)
return path.split_view('/');
}
OwnPtr<KString> try_join(StringView const& first, StringView const& second)
KResultOr<NonnullOwnPtr<KString>> try_join(StringView const& first, StringView const& second)
{
VERIFY(is_canonical(first));
VERIFY(is_canonical(second));
@ -70,24 +70,19 @@ OwnPtr<KString> try_join(StringView const& first, StringView const& second)
if (first == "/"sv) {
char* buffer;
auto string = KString::try_create_uninitialized(1 + second.length(), buffer);
if (!string)
return {};
auto string = TRY(KString::try_create_uninitialized(1 + second.length(), buffer));
buffer[0] = '/';
__builtin_memcpy(buffer + 1, second.characters_without_null_termination(), second.length());
buffer[string->length()] = 0;
return string;
} else {
char* buffer;
auto string = KString::try_create_uninitialized(first.length() + 1 + second.length(), buffer);
if (!string)
return string;
__builtin_memcpy(buffer, first.characters_without_null_termination(), first.length());
buffer[first.length()] = '/';
__builtin_memcpy(buffer + first.length() + 1, second.characters_without_null_termination(), second.length());
buffer[string->length()] = 0;
return string;
}
char* buffer;
auto string = TRY(KString::try_create_uninitialized(first.length() + 1 + second.length(), buffer));
__builtin_memcpy(buffer, first.characters_without_null_termination(), first.length());
buffer[first.length()] = '/';
__builtin_memcpy(buffer + first.length() + 1, second.characters_without_null_termination(), second.length());
buffer[string->length()] = 0;
return string;
}
}