mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +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
|
@ -35,7 +35,7 @@ CSVExportDialogPage::CSVExportDialogPage(const Sheet& sheet)
|
|||
m_headers.extend(m_data.take_first());
|
||||
|
||||
auto temp_template = String::formatted("{}/spreadsheet-csv-export.{}.XXXXXX", Core::StandardPaths::tempfile_directory(), getpid());
|
||||
auto temp_path = ByteBuffer::create_uninitialized(temp_template.length() + 1);
|
||||
auto temp_path = ByteBuffer::create_uninitialized(temp_template.length() + 1).release_value();
|
||||
auto buf = reinterpret_cast<char*>(temp_path.data());
|
||||
auto copy_ok = temp_template.copy_characters_to_buffer(buf, temp_path.size());
|
||||
VERIFY(copy_ok);
|
||||
|
|
|
@ -85,7 +85,7 @@ BENCHMARK_CASE(fairly_big_data)
|
|||
{
|
||||
constexpr auto num_rows = 100000u;
|
||||
constexpr auto line = "well,hello,friends,1,2,3,4,5,6,7,8,pizza,guacamole\n"sv;
|
||||
auto buf = ByteBuffer::create_uninitialized((line.length() * num_rows) + 1);
|
||||
auto buf = ByteBuffer::create_uninitialized((line.length() * num_rows) + 1).release_value();
|
||||
buf[buf.size() - 1] = '\0';
|
||||
|
||||
for (size_t row = 0; row <= num_rows; ++row) {
|
||||
|
|
|
@ -18,7 +18,7 @@ TEST_CASE(can_write)
|
|||
{ 7, 8, 9 },
|
||||
};
|
||||
|
||||
auto buffer = ByteBuffer::create_uninitialized(1024);
|
||||
auto buffer = ByteBuffer::create_uninitialized(1024).release_value();
|
||||
OutputMemoryStream stream { buffer };
|
||||
|
||||
Writer::CSV csv(stream, data);
|
||||
|
@ -39,7 +39,7 @@ TEST_CASE(can_write_with_header)
|
|||
{ 7, 8, 9 },
|
||||
};
|
||||
|
||||
auto buffer = ByteBuffer::create_uninitialized(1024);
|
||||
auto buffer = ByteBuffer::create_uninitialized(1024).release_value();
|
||||
OutputMemoryStream stream { buffer };
|
||||
|
||||
Writer::CSV csv(stream, data, { "A", "B\"", "C" });
|
||||
|
@ -60,7 +60,7 @@ TEST_CASE(can_write_with_different_behaviours)
|
|||
{ "We\"ll", "Hello,", " Friends" },
|
||||
};
|
||||
|
||||
auto buffer = ByteBuffer::create_uninitialized(1024);
|
||||
auto buffer = ByteBuffer::create_uninitialized(1024).release_value();
|
||||
OutputMemoryStream stream { buffer };
|
||||
|
||||
Writer::CSV csv(stream, data, { "A", "B\"", "C" }, Writer::WriterBehaviour::QuoteOnlyInFieldStart | Writer::WriterBehaviour::WriteHeaders);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue