summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-03-01 17:24:50 +0100
committerLinus Groh <mail@linusgroh.de>2023-03-13 15:16:20 +0000
commitae51c1821c0d32ba40b866d8e5561f6de3359b17 (patch)
tree6bd2d0964841bf5bd56797ad4a887e8e4e3ac63c /Userland/Libraries
parent26516ee1601b0662bb1753f834a179bf1a20082d (diff)
downloadserenity-ae51c1821c0d32ba40b866d8e5561f6de3359b17.zip
Everywhere: Remove unintentional partial stream reads and writes
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.cpp4
-rw-r--r--Userland/Libraries/LibCompress/Deflate.cpp6
-rw-r--r--Userland/Libraries/LibCompress/Gzip.cpp21
-rw-r--r--Userland/Libraries/LibCompress/Zlib.cpp6
-rw-r--r--Userland/Libraries/LibCore/ConfigFile.cpp7
-rw-r--r--Userland/Libraries/LibCore/EventLoop.cpp4
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp5
-rw-r--r--Userland/Libraries/LibIMAP/Client.cpp8
-rw-r--r--Userland/Libraries/LibJS/Console.cpp3
-rw-r--r--Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp17
-rw-r--r--Userland/Libraries/LibSQL/SQLClient.cpp3
-rw-r--r--Userland/Libraries/LibTest/JavaScriptTestRunner.h3
-rw-r--r--Userland/Libraries/LibWeb/WebDriver/Client.cpp8
13 files changed, 34 insertions, 61 deletions
diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp
index 3a5274f649..ffdb8e5508 100644
--- a/Userland/Libraries/LibAudio/MP3Loader.cpp
+++ b/Userland/Libraries/LibAudio/MP3Loader.cpp
@@ -233,9 +233,7 @@ ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_frame_data(MP3::Header
size_t old_reservoir_size = m_bit_reservoir.used_buffer_size();
LOADER_TRY(m_bitstream->read_until_filled(buffer));
- // FIXME: This should write the entire span.
- if (LOADER_TRY(m_bit_reservoir.write_some(buffer)) != header.slot_count)
- return LoaderError { LoaderError::Category::IO, m_loaded_samples, "Could not write frame into bit reservoir." };
+ LOADER_TRY(m_bit_reservoir.write_until_depleted(buffer));
// If we don't have enough data in the reservoir to process this frame, skip it (but keep the data).
if (old_reservoir_size < static_cast<size_t>(frame.main_data_begin))
diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp
index e7a8494305..8660163951 100644
--- a/Userland/Libraries/LibCompress/Deflate.cpp
+++ b/Userland/Libraries/LibCompress/Deflate.cpp
@@ -225,10 +225,8 @@ ErrorOr<Bytes> DeflateDecompressor::read_some(Bytes bytes)
if (block_type == 0b00) {
m_input_stream->align_to_byte_boundary();
- // FIXME: This should read the entire span.
- LittleEndian<u16> length, negated_length;
- TRY(m_input_stream->read_some(length.bytes()));
- TRY(m_input_stream->read_some(negated_length.bytes()));
+ u16 length = TRY(m_input_stream->read_value<LittleEndian<u16>>());
+ u16 negated_length = TRY(m_input_stream->read_value<LittleEndian<u16>>());
if ((length ^ 0xffff) != negated_length)
return Error::from_string_literal("Calculated negated length does not equal stored negated length");
diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp
index c5abab5657..fce7a5fc09 100644
--- a/Userland/Libraries/LibCompress/Gzip.cpp
+++ b/Userland/Libraries/LibCompress/Gzip.cpp
@@ -75,10 +75,8 @@ ErrorOr<Bytes> GzipDecompressor::read_some(Bytes bytes)
current_member().m_nread += current_slice.size();
if (current_slice.size() < slice.size()) {
- // FIXME: This should read the entire span.
- LittleEndian<u32> crc32, input_size;
- TRY(m_input_stream->read_some(crc32.bytes()));
- TRY(m_input_stream->read_some(input_size.bytes()));
+ u32 crc32 = TRY(m_input_stream->read_value<LittleEndian<u32>>());
+ u32 input_size = TRY(m_input_stream->read_value<LittleEndian<u32>>());
if (crc32 != current_member().m_checksum.digest())
return Error::from_string_literal("Stored CRC32 does not match the calculated CRC32 of the current member");
@@ -116,18 +114,16 @@ ErrorOr<Bytes> GzipDecompressor::read_some(Bytes bytes)
return Error::from_string_literal("Header is not supported by implementation");
if (header.flags & Flags::FEXTRA) {
- // FIXME: This should read the entire span.
- LittleEndian<u16> subfield_id, length;
- TRY(m_input_stream->read_some(subfield_id.bytes()));
- TRY(m_input_stream->read_some(length.bytes()));
+ u16 subfield_id = TRY(m_input_stream->read_value<LittleEndian<u16>>());
+ u16 length = TRY(m_input_stream->read_value<LittleEndian<u16>>());
TRY(m_input_stream->discard(length));
+ (void)subfield_id;
}
auto discard_string = [&]() -> ErrorOr<void> {
char next_char;
do {
- // FIXME: This should read the entire span.
- TRY(m_input_stream->read_some({ &next_char, sizeof(next_char) }));
+ next_char = TRY(m_input_stream->read_value<char>());
} while (next_char);
return {};
@@ -140,10 +136,9 @@ ErrorOr<Bytes> GzipDecompressor::read_some(Bytes bytes)
TRY(discard_string());
if (header.flags & Flags::FHCRC) {
- // FIXME: This should read the entire span.
- LittleEndian<u16> crc16;
- TRY(m_input_stream->read_some(crc16.bytes()));
+ u16 crc = TRY(m_input_stream->read_value<LittleEndian<u16>>());
// FIXME: we should probably verify this instead of just assuming it matches
+ (void)crc;
}
m_current_member = TRY(Member::construct(header, *m_input_stream));
diff --git a/Userland/Libraries/LibCompress/Zlib.cpp b/Userland/Libraries/LibCompress/Zlib.cpp
index ccf30ec89a..91f8413460 100644
--- a/Userland/Libraries/LibCompress/Zlib.cpp
+++ b/Userland/Libraries/LibCompress/Zlib.cpp
@@ -113,8 +113,7 @@ ErrorOr<void> ZlibCompressor::write_header(ZlibCompressionMethod compression_met
// FIXME: Support pre-defined dictionaries.
- // FIXME: This should write the entire span.
- TRY(m_output_stream->write_some(header.as_u16.bytes()));
+ TRY(m_output_stream->write_until_depleted(header.as_u16.bytes()));
return {};
}
@@ -155,8 +154,7 @@ ErrorOr<void> ZlibCompressor::finish()
TRY(static_cast<DeflateCompressor*>(m_compressor.ptr())->final_flush());
NetworkOrdered<u32> adler_sum = m_adler32_checksum.digest();
- // FIXME: This should write the entire span.
- TRY(m_output_stream->write_some(adler_sum.bytes()));
+ TRY(m_output_stream->write_value(adler_sum));
m_finished = true;
diff --git a/Userland/Libraries/LibCore/ConfigFile.cpp b/Userland/Libraries/LibCore/ConfigFile.cpp
index faa333a225..a302fd9b46 100644
--- a/Userland/Libraries/LibCore/ConfigFile.cpp
+++ b/Userland/Libraries/LibCore/ConfigFile.cpp
@@ -179,11 +179,10 @@ ErrorOr<void> ConfigFile::sync()
TRY(m_file->seek(0, SeekMode::SetPosition));
for (auto& it : m_groups) {
- // FIXME: This should write the entire span.
- TRY(m_file->write_some(DeprecatedString::formatted("[{}]\n", it.key).bytes()));
+ TRY(m_file->write_until_depleted(DeprecatedString::formatted("[{}]\n", it.key).bytes()));
for (auto& jt : it.value)
- TRY(m_file->write_some(DeprecatedString::formatted("{}={}\n", jt.key, jt.value).bytes()));
- TRY(m_file->write_some("\n"sv.bytes()));
+ TRY(m_file->write_until_depleted(DeprecatedString::formatted("{}={}\n", jt.key, jt.value).bytes()));
+ TRY(m_file->write_until_depleted("\n"sv.bytes()));
}
m_dirty = false;
diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp
index b5a0c98521..149360e181 100644
--- a/Userland/Libraries/LibCore/EventLoop.cpp
+++ b/Userland/Libraries/LibCore/EventLoop.cpp
@@ -221,9 +221,7 @@ public:
auto bytes_to_send = serialized.bytes();
u32 length = bytes_to_send.size();
// FIXME: Propagate errors
- // FIXME: This should write the entire span.
- auto sent = MUST(m_socket->write_some({ (u8 const*)&length, sizeof(length) }));
- VERIFY(sent == sizeof(length));
+ MUST(m_socket->write_value(length));
while (!bytes_to_send.is_empty()) {
size_t bytes_sent = MUST(m_socket->write_some(bytes_to_send));
bytes_to_send = bytes_to_send.slice(bytes_sent);
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 74482ed7bb..8a9cf9ee86 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -1593,9 +1593,8 @@ ErrorOr<void> TextEditor::write_to_file(Core::File& file)
// A size 0 file doesn't need a data copy.
} else {
for (size_t i = 0; i < line_count(); ++i) {
- // FIXME: This should write the entire span.
- TRY(file.write_some(line(i).to_utf8().bytes()));
- TRY(file.write_some("\n"sv.bytes()));
+ TRY(file.write_until_depleted(line(i).to_utf8().bytes()));
+ TRY(file.write_until_depleted("\n"sv.bytes()));
}
}
document().set_unmodified();
diff --git a/Userland/Libraries/LibIMAP/Client.cpp b/Userland/Libraries/LibIMAP/Client.cpp
index e952e73ca9..753af26ad9 100644
--- a/Userland/Libraries/LibIMAP/Client.cpp
+++ b/Userland/Libraries/LibIMAP/Client.cpp
@@ -60,8 +60,7 @@ ErrorOr<void> Client::on_ready_to_receive()
auto pending_bytes = TRY(m_socket->pending_bytes());
auto receive_buffer = TRY(m_buffer.get_bytes_for_writing(pending_bytes));
- // FIXME: This should read the entire span.
- TRY(m_socket->read_some(receive_buffer));
+ TRY(m_socket->read_until_filled(receive_buffer));
// Once we get server hello we can start sending.
if (m_connect_pending) {
@@ -146,9 +145,8 @@ static ReadonlyBytes command_byte_buffer(CommandType command)
ErrorOr<void> Client::send_raw(StringView data)
{
- // FIXME: This should write the entire span.
- TRY(m_socket->write_some(data.bytes()));
- TRY(m_socket->write_some("\r\n"sv.bytes()));
+ TRY(m_socket->write_until_depleted(data.bytes()));
+ TRY(m_socket->write_until_depleted("\r\n"sv.bytes()));
return {};
}
diff --git a/Userland/Libraries/LibJS/Console.cpp b/Userland/Libraries/LibJS/Console.cpp
index cc3af07d97..c977452cc2 100644
--- a/Userland/Libraries/LibJS/Console.cpp
+++ b/Userland/Libraries/LibJS/Console.cpp
@@ -680,8 +680,7 @@ ThrowCompletionOr<String> ConsoleClient::generically_format_values(MarkedVector<
bool first = true;
for (auto const& value : values) {
if (!first)
- // FIXME: This should write the entire span.
- TRY_OR_THROW_OOM(vm, stream.write_some(" "sv.bytes()));
+ TRY_OR_THROW_OOM(vm, stream.write_until_depleted(" "sv.bytes()));
TRY_OR_THROW_OOM(vm, JS::print(value, ctx));
first = false;
}
diff --git a/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp b/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp
index 98833292f0..fbb8a552ff 100644
--- a/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp
+++ b/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp
@@ -51,8 +51,7 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
// the suggestion list to fit in the prompt line.
auto start = max_line_count - m_prompt_lines_at_suggestion_initiation;
for (size_t i = start; i < max_line_count; ++i)
- // FIXME: This should write the entire span.
- TRY(stderr_stream->write_some("\n"sv.bytes()));
+ TRY(stderr_stream->write_until_depleted("\n"sv.bytes()));
lines_used += max_line_count;
longest_suggestion_length = 0;
}
@@ -100,8 +99,7 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
if (next_column > m_num_columns) {
auto lines = (suggestion.text_view.length() + m_num_columns - 1) / m_num_columns;
lines_used += lines;
- // FIXME: This should write the entire span.
- TRY(stderr_stream->write_some("\n"sv.bytes()));
+ TRY(stderr_stream->write_until_depleted("\n"sv.bytes()));
num_printed = 0;
}
@@ -117,13 +115,11 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
if (spans_entire_line) {
num_printed += m_num_columns;
- // FIXME: This should write the entire span.
- TRY(stderr_stream->write_some(suggestion.text_string.bytes()));
- TRY(stderr_stream->write_some(suggestion.display_trivia_string.bytes()));
+ TRY(stderr_stream->write_until_depleted(suggestion.text_string.bytes()));
+ TRY(stderr_stream->write_until_depleted(suggestion.display_trivia_string.bytes()));
} else {
auto field = DeprecatedString::formatted("{: <{}} {}", suggestion.text_string, longest_suggestion_byte_length_without_trivia, suggestion.display_trivia_string);
- // FIXME: This should write the entire span.
- TRY(stderr_stream->write_some(DeprecatedString::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes()));
+ TRY(stderr_stream->write_until_depleted(DeprecatedString::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes()));
num_printed += longest_suggestion_length + 2;
}
@@ -154,8 +150,7 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
TRY(VT::move_absolute(m_origin_row + lines_used, m_num_columns - string.length() - 1, *stderr_stream));
TRY(VT::apply_style({ Style::Background(Style::XtermColor::Green) }, *stderr_stream));
- // FIXME: This should write the entire span.
- TRY(stderr_stream->write_some(string.bytes()));
+ TRY(stderr_stream->write_until_depleted(string.bytes()));
TRY(VT::apply_style(Style::reset_style(), *stderr_stream));
}
diff --git a/Userland/Libraries/LibSQL/SQLClient.cpp b/Userland/Libraries/LibSQL/SQLClient.cpp
index 44e11cdd90..db9455b83e 100644
--- a/Userland/Libraries/LibSQL/SQLClient.cpp
+++ b/Userland/Libraries/LibSQL/SQLClient.cpp
@@ -67,8 +67,7 @@ static ErrorOr<void> launch_server(DeprecatedString const& socket_path, Deprecat
if (server_pid != 0) {
auto server_pid_file = TRY(Core::File::open(pid_path, Core::File::OpenMode::Write));
- // FIXME: This should write the entire span.
- TRY(server_pid_file->write_some(DeprecatedString::number(server_pid).bytes()));
+ TRY(server_pid_file->write_until_depleted(DeprecatedString::number(server_pid).bytes()));
TRY(Core::System::kill(getpid(), SIGTERM));
}
diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h
index fd944a90c9..738172ef54 100644
--- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h
+++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h
@@ -220,8 +220,7 @@ inline ByteBuffer load_entire_file(StringView path)
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
auto file_size = TRY(file->size());
auto content = TRY(ByteBuffer::create_uninitialized(file_size));
- // FIXME: This should read the entire span.
- TRY(file->read_some(content.bytes()));
+ TRY(file->read_until_filled(content.bytes()));
return content;
};
diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp
index 99b645bb65..6161e8b61f 100644
--- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp
+++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp
@@ -279,8 +279,7 @@ ErrorOr<void, Client::WrappedError> Client::send_success_response(JsonValue resu
builder.append("\r\n"sv);
auto builder_contents = TRY(builder.to_byte_buffer());
- // FIXME: This should write the entire span.
- TRY(m_socket->write_some(builder_contents));
+ TRY(m_socket->write_until_depleted(builder_contents));
while (!content.is_empty()) {
auto bytes_sent = TRY(m_socket->write_some(content.bytes()));
@@ -320,9 +319,8 @@ ErrorOr<void, Client::WrappedError> Client::send_error_response(Error const& err
header_builder.appendff("Content-Length: {}\r\n", content_builder.length());
header_builder.append("\r\n"sv);
- // FIXME: This should write the entire span.
- TRY(m_socket->write_some(TRY(header_builder.to_byte_buffer())));
- TRY(m_socket->write_some(TRY(content_builder.to_byte_buffer())));
+ TRY(m_socket->write_until_depleted(TRY(header_builder.to_byte_buffer())));
+ TRY(m_socket->write_until_depleted(TRY(content_builder.to_byte_buffer())));
log_response(error.http_status);
return {};