diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-06 03:28:46 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 01:53:26 +0200 |
commit | 3a9f00c59bad7735970c72cb940d08161fda09b0 (patch) | |
tree | 5eebf972a2a3b3c2e73d40068f4d58c9d6368764 /Userland/Utilities | |
parent | 6606993432273959d7b2e1815646ee8a54025103 (diff) | |
download | serenity-3a9f00c59bad7735970c72cb940d08161fda09b0.zip |
Everywhere: Use OOM-safe ByteBuffer APIs where possible
If we can easily communicate failure, let's avoid asserting and report
failure instead.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/pro.cpp | 3 | ||||
-rw-r--r-- | Userland/Utilities/test-crypto.cpp | 10 |
2 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Utilities/pro.cpp b/Userland/Utilities/pro.cpp index 7556eb7a17..6bf653d1bc 100644 --- a/Userland/Utilities/pro.cpp +++ b/Userland/Utilities/pro.cpp @@ -122,7 +122,8 @@ private: { if (!m_condition()) { write_to_buffer:; - m_buffer.append(bytes.data(), bytes.size()); + if (!m_buffer.try_append(bytes.data(), bytes.size())) + return 0; return bytes.size(); } diff --git a/Userland/Utilities/test-crypto.cpp b/Userland/Utilities/test-crypto.cpp index 82338909c7..f096442bcc 100644 --- a/Userland/Utilities/test-crypto.cpp +++ b/Userland/Utilities/test-crypto.cpp @@ -165,8 +165,9 @@ static void tls(const char* message, size_t len) g_loop.quit(0); }; } - write.append(message, len); - write.append("\r\n", 2); + auto ok = write.try_append(message, len); + ok = ok && write.try_append("\r\n", 2); + VERIFY(ok); } static void aes_cbc(const char* message, size_t len) @@ -2037,7 +2038,10 @@ static void tls_test_client_hello() loop.quit(1); } else { // print_buffer(data.value(), 16); - contents.append(data.value().data(), data.value().size()); + if (!contents.try_append(data.value().data(), data.value().size())) { + FAIL(Allocation failed); + loop.quit(1); + } } }; tls->on_tls_finished = [&] { |