1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:27:46 +00:00

AK/ByteBuffer+Everywhere: Handle errors in ByteBuffer::slice()

This commit is contained in:
Matthias Zimmerman 2022-06-13 05:20:42 -07:00 committed by Linus Groh
parent c0486f93d4
commit c10d48b72c
12 changed files with 45 additions and 34 deletions

View file

@ -64,7 +64,8 @@ ByteBuffer Job::receive(size_t size)
{
ByteBuffer buffer = ByteBuffer::create_uninitialized(size).release_value_but_fixme_should_propagate_errors();
auto nread = MUST(m_socket->read(buffer)).size();
return buffer.slice(0, nread);
// FIXME: Propagate errors.
return MUST(buffer.slice(0, nread));
}
bool Job::can_read() const
@ -101,7 +102,8 @@ void Job::flush_received_buffers()
continue;
}
VERIFY(written < payload.size());
payload = payload.slice(written, payload.size() - written);
// FIXME: Propagate errors.
payload = MUST(payload.slice(written, payload.size() - written));
return;
}
}

View file

@ -130,7 +130,8 @@ Value ArrayBuffer::get_value(size_t byte_index, [[maybe_unused]] bool is_typed_a
// FIXME: Check for shared buffer
auto raw_value = buffer_impl().slice(byte_index, element_size);
// FIXME: Propagate errors.
auto raw_value = MUST(buffer_impl().slice(byte_index, element_size));
return raw_bytes_to_numeric<T>(global_object(), move(raw_value), is_little_endian);
}
@ -218,7 +219,8 @@ Value ArrayBuffer::get_modify_set_value(size_t byte_index, Value value, ReadWrit
// FIXME: Check for shared buffer
auto raw_bytes_read = buffer_impl().slice(byte_index, sizeof(T));
// FIXME: Propagate errors.
auto raw_bytes_read = MUST(buffer_impl().slice(byte_index, sizeof(T)));
auto raw_bytes_modified = operation(raw_bytes_read, raw_bytes);
raw_bytes_modified.span().copy_to(buffer_impl().span().slice(byte_index));

View file

@ -246,7 +246,8 @@ static ThrowCompletionOr<Value> atomic_compare_exchange_impl(GlobalObject& globa
// 14. Else,
// a. Let rawBytesRead be a List of length elementSize whose elements are the sequence of elementSize bytes starting with block[indexedPosition].
auto raw_bytes_read = block.slice(indexed_position, sizeof(T));
// FIXME: Propagate errors.
auto raw_bytes_read = MUST(block.slice(indexed_position, sizeof(T)));
// b. If ByteListEqual(rawBytesRead, expectedBytes) is true, then
// i. Store the individual bytes of replacementBytes into block, starting at block[indexedPosition].

View file

@ -202,7 +202,7 @@ constexpr static int USER_VALUES_OFFSET = 32;
ErrorOr<void> Heap::read_zero_block()
{
auto buffer = TRY(read_block(0));
auto file_id_buffer = buffer.slice(0, FILE_ID.length());
auto file_id_buffer = TRY(buffer.slice(0, FILE_ID.length()));
auto file_id = StringView(file_id_buffer);
if (file_id != FILE_ID) {
warnln("{}: Zero page corrupt. This is probably not a {} heap file"sv, name(), FILE_ID);

View file

@ -27,8 +27,8 @@ ErrorOr<Bytes> TLSv12::read(Bytes bytes)
return Bytes {};
}
m_context.application_buffer.span().slice(0, size_to_read).copy_to(bytes);
m_context.application_buffer = m_context.application_buffer.slice(size_to_read, m_context.application_buffer.size() - size_to_read);
TRY(m_context.application_buffer.slice(0, size_to_read)).span().copy_to(bytes);
m_context.application_buffer = TRY(m_context.application_buffer.slice(size_to_read, m_context.application_buffer.size() - size_to_read));
return Bytes { bytes.data(), size_to_read };
}
@ -47,7 +47,8 @@ String TLSv12::read_line(size_t max_size)
return {};
String line { bit_cast<char const*>(start), offset, Chomp };
m_context.application_buffer = m_context.application_buffer.slice(offset + 1, m_context.application_buffer.size() - offset - 1);
// FIXME: Propagate errors.
m_context.application_buffer = MUST(m_context.application_buffer.slice(offset + 1, m_context.application_buffer.size() - offset - 1));
return line;
}

View file

@ -85,7 +85,8 @@ public:
{
auto length = m_current_length;
m_current_length = 0;
return m_packet_data.slice(0, length);
// FIXME: Propagate errors.
return MUST(m_packet_data.slice(0, length));
}
inline void set(size_t offset, u8 value)
{

View file

@ -92,7 +92,8 @@ void TLSv12::consume(ReadonlyBytes record)
}
if (index) {
m_context.message_buffer = m_context.message_buffer.slice(index, m_context.message_buffer.size() - index);
// FIXME: Propagate errors.
m_context.message_buffer = MUST(m_context.message_buffer.slice(index, m_context.message_buffer.size() - index));
}
}