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

Everywhere: Use OOM-safe ByteBuffer APIs where possible

If we can easily communicate failure, let's avoid asserting and report
failure instead.
This commit is contained in:
Ali Mohammad Pur 2021-09-06 03:28:46 +04:30 committed by Andreas Kling
parent 6606993432
commit 3a9f00c59b
22 changed files with 135 additions and 67 deletions

View file

@ -349,7 +349,8 @@ public:
return false;
}
auto previous_size = m_size;
m_data.resize(new_size);
if (!m_data.try_resize(new_size))
return false;
m_size = new_size;
// The spec requires that we zero out everything on grow
__builtin_memset(m_data.offset_pointer(previous_size), 0, size_to_grow);

View file

@ -744,7 +744,8 @@ ParseResult<CustomSection> CustomSection::parse(InputStream& stream)
auto size = stream.read({ buf, 16 });
if (size == 0)
break;
data_buffer.append(buf, size);
if (!data_buffer.try_append(buf, size))
return with_eof_check(stream, ParseError::HugeAllocationRequested);
}
return CustomSection(name.release_value(), move(data_buffer));