mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:27:45 +00:00
Everywhere: Remove unintentional partial stream reads and writes
This commit is contained in:
parent
26516ee160
commit
ae51c1821c
44 changed files with 109 additions and 192 deletions
|
@ -28,8 +28,7 @@ static ErrorOr<bool> format_file(StringView path, bool inplace)
|
|||
return true;
|
||||
TRY(file->seek(0, SeekMode::SetPosition));
|
||||
TRY(file->truncate(0));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(file->write_some(formatted_gml.bytes()));
|
||||
TRY(file->write_until_depleted(formatted_gml.bytes()));
|
||||
} else {
|
||||
out("{}", formatted_gml);
|
||||
}
|
||||
|
|
|
@ -174,8 +174,7 @@ static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Cor
|
|||
|
||||
auto output_file = MUST(Core::File::open(output_file_path, Core::File::OpenMode::Write));
|
||||
auto image_buffer = MUST(Gfx::PNGWriter::encode(*screenshot));
|
||||
// FIXME: This should write the entire buffer.
|
||||
MUST(output_file->write_some(image_buffer.bytes()));
|
||||
MUST(output_file->write_until_depleted(image_buffer.bytes()));
|
||||
} else {
|
||||
warnln("No screenshot available");
|
||||
}
|
||||
|
|
|
@ -188,8 +188,7 @@ static ErrorOr<void> write_to_file(String const& path)
|
|||
for (size_t i = 0; i < g_repl_statements.size(); i++) {
|
||||
auto line = g_repl_statements[i].bytes();
|
||||
if (line.size() > 0 && i != g_repl_statements.size() - 1) {
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(file->write_some(line));
|
||||
TRY(file->write_until_depleted(line));
|
||||
}
|
||||
if (i != g_repl_statements.size() - 1) {
|
||||
TRY(file->write_value('\n'));
|
||||
|
|
|
@ -82,8 +82,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto nread = TRY(Core::System::read(STDIN_FILENO, buffer_span));
|
||||
buffer_span = buffer_span.trim(nread);
|
||||
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(socket->write_some({ buffer_span.data(), static_cast<size_t>(nread) }));
|
||||
TRY(socket->write_until_depleted({ buffer_span.data(), static_cast<size_t>(nread) }));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
|||
auto file = TRY(Core::File::open("/sys/kernel/power_state"sv, Core::File::OpenMode::Write));
|
||||
|
||||
const DeprecatedString file_contents = "1";
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(file->write_some(file_contents.bytes()));
|
||||
TRY(file->write_until_depleted(file_contents.bytes()));
|
||||
file->close();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -141,9 +141,8 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
|
||||
if (maybe_output_file.has_value()) {
|
||||
auto const& output_file = maybe_output_file.value();
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(output_file->write_some(result.bytes()));
|
||||
TRY(output_file->write_some("\n"sv.bytes()));
|
||||
TRY(output_file->write_until_depleted(result.bytes()));
|
||||
TRY(output_file->write_until_depleted("\n"sv.bytes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,8 +167,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
auto& file = *file_or_error.value();
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(file.write_some(encoded_bitmap.bytes()));
|
||||
TRY(file.write_until_depleted(encoded_bitmap.bytes()));
|
||||
|
||||
if (edit_image)
|
||||
TRY(Core::Process::spawn("/bin/PixelPaint"sv, Array { output_path }));
|
||||
|
|
|
@ -18,8 +18,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
|||
auto file = TRY(Core::File::open("/sys/kernel/power_state"sv, Core::File::OpenMode::Write));
|
||||
|
||||
const DeprecatedString file_contents = "2";
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(file->write_some(file_contents.bytes()));
|
||||
TRY(file->write_until_depleted(file_contents.bytes()));
|
||||
file->close();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -932,7 +932,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
FormattedSyscallBuilder builder(syscall_name);
|
||||
TRY(format_syscall(builder, syscall_function, arg1, arg2, arg3, res));
|
||||
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(trace_file->write_some(builder.string_view().bytes()));
|
||||
TRY(trace_file->write_until_depleted(builder.string_view().bytes()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,8 +48,7 @@ static bool write_variable(StringView name, StringView value)
|
|||
warnln("Failed to open {}: {}", path, file.error());
|
||||
return false;
|
||||
}
|
||||
// FIXME: This should write the entire span.
|
||||
if (auto result = file.value()->write_some(value.bytes()); result.is_error()) {
|
||||
if (auto result = file.value()->write_until_depleted(value.bytes()); result.is_error()) {
|
||||
warnln("Failed to write {}: {}", path, result.error());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,10 +34,8 @@ static ErrorOr<off_t> find_seek_pos(Core::File& file, int wanted_lines)
|
|||
|
||||
if (file.is_eof())
|
||||
break;
|
||||
Array<u8, 1> buffer;
|
||||
// FIXME: This should read the entire span.
|
||||
auto ch = TRY(file.read_some(buffer));
|
||||
if (*ch.data() == '\n' && (end - pos) > 1) {
|
||||
auto ch = TRY(file.read_value<u8>());
|
||||
if (ch == '\n' && (end - pos) > 1) {
|
||||
lines++;
|
||||
if (lines == wanted_lines)
|
||||
break;
|
||||
|
|
|
@ -17,11 +17,10 @@ static ErrorOr<void> write_line_content(StringView line, size_t count, bool dupl
|
|||
if (duplicates_only && count <= 1)
|
||||
return {};
|
||||
|
||||
// FIXME: This should write the entire span.
|
||||
if (print_count)
|
||||
TRY(outfile.write_some(DeprecatedString::formatted("{} {}\n", count, line).bytes()));
|
||||
TRY(outfile.write_until_depleted(DeprecatedString::formatted("{} {}\n", count, line).bytes()));
|
||||
else
|
||||
TRY(outfile.write_some(DeprecatedString::formatted("{}\n", line).bytes()));
|
||||
TRY(outfile.write_until_depleted(DeprecatedString::formatted("{}\n", line).bytes()));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
TRY(file->seek(0, SeekMode::SetPosition));
|
||||
TRY(file->truncate(0));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(file->write_some(json.to_deprecated_string().bytes()));
|
||||
TRY(file->write_until_depleted(json.to_deprecated_string().bytes()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -53,14 +53,12 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
|
|||
if (always_print_stack)
|
||||
config.dump_stack();
|
||||
if (always_print_instruction) {
|
||||
// FIXME: This should write the entire span.
|
||||
g_stdout->write_some(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_printer->print(instr);
|
||||
}
|
||||
if (g_continue)
|
||||
return true;
|
||||
// FIXME: This should write the entire span.
|
||||
g_stdout->write_some(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(DeprecatedString::formatted("{:0>4} ", ip.value()).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_printer->print(instr);
|
||||
DeprecatedString last_command = "";
|
||||
for (;;) {
|
||||
|
@ -216,8 +214,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
|
|||
if (!result.values().is_empty())
|
||||
warnln("Returned:");
|
||||
for (auto& value : result.values()) {
|
||||
// FIXME: This should write the entire span.
|
||||
g_stdout->write_some(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_printer->print(value);
|
||||
}
|
||||
}
|
||||
|
@ -457,18 +454,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto print_func = [&](auto const& address) {
|
||||
Wasm::FunctionInstance* fn = machine.store().get(address);
|
||||
// FIXME: This should write the entire span.
|
||||
g_stdout->write_some(DeprecatedString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(DeprecatedString::formatted("- Function with address {}, ptr = {}\n", address.value(), fn).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
if (fn) {
|
||||
// FIXME: This should write the entire span.
|
||||
g_stdout->write_some(DeprecatedString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>()).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(DeprecatedString::formatted(" wasm function? {}\n", fn->has<Wasm::WasmFunction>()).bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
fn->visit(
|
||||
[&](Wasm::WasmFunction const& func) {
|
||||
Wasm::Printer printer { *g_stdout, 3 };
|
||||
// FIXME: This should write the entire span.
|
||||
g_stdout->write_some(" type:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(" type:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
printer.print(func.type());
|
||||
g_stdout->write_some(" code:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(" code:\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
printer.print(func.code());
|
||||
},
|
||||
[](Wasm::HostFunction const&) {});
|
||||
|
@ -532,8 +526,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (!result.values().is_empty())
|
||||
warnln("Returned:");
|
||||
for (auto& value : result.values()) {
|
||||
// FIXME: This should write the entire span.
|
||||
g_stdout->write_some(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_stdout->write_until_depleted(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
g_printer->print(value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue