mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 07:54:58 +00:00
Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe
This commit is contained in:
parent
3a9f00c59b
commit
97e97bccab
105 changed files with 629 additions and 290 deletions
|
@ -20,7 +20,11 @@ Optional<ByteBuffer> decode_hex(const StringView& input)
|
|||
if ((input.length() % 2) != 0)
|
||||
return {};
|
||||
|
||||
auto output = ByteBuffer::create_zeroed(input.length() / 2);
|
||||
auto output_result = ByteBuffer::create_zeroed(input.length() / 2);
|
||||
if (!output_result.has_value())
|
||||
return {};
|
||||
|
||||
auto& output = output_result.value();
|
||||
|
||||
for (size_t i = 0; i < input.length() / 2; ++i) {
|
||||
const auto c1 = decode_hex_digit(input[i * 2]);
|
||||
|
@ -34,7 +38,7 @@ Optional<ByteBuffer> decode_hex(const StringView& input)
|
|||
output[i] = (c1 << 4) + c2;
|
||||
}
|
||||
|
||||
return output;
|
||||
return output_result;
|
||||
}
|
||||
|
||||
String encode_hex(const ReadonlyBytes input)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue