Skip to content

Commit 84787aa

Browse files
committed
uefi: serial: fix core::fmt::Write impl
This is the more expected and natural behavior.
1 parent b3b3310 commit 84787aa

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

uefi-test-runner/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern crate alloc;
1010

1111
use alloc::string::ToString;
1212
use alloc::vec::Vec;
13+
use core::fmt::Write;
1314
use uefi::mem::memory_map::MemoryMap;
1415
use uefi::prelude::*;
1516
use uefi::proto::console::serial::Serial;
@@ -115,7 +116,10 @@ fn send_request_helper(serial: &mut Serial, request: HostRequest) -> Result {
115116
serial.set_attributes(&io_mode)?;
116117

117118
// Send a screenshot request to the host.
118-
serial.write(request.as_bytes()).discard_errdata()?;
119+
//serial.write(request.as_bytes()).discard_errdata()?;
120+
serial
121+
.write_str(request.as_str())
122+
.expect("should write all bytes");
119123

120124
// Wait for the host's acknowledgement before moving forward.
121125
let mut reply = [0; 3];

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
return `n` in any case. In the happy path, this always corresponds to the
3131
length if the provided data/buffer, but helps to cope with non-spec-compliant
3232
implementations.
33+
- Fixed potential partial writes in `core::fmt::Write` impl of `Serial` protocol
3334

3435
# uefi - v0.36.1 (2025-11-05)
3536

uefi/src/proto/console/serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,6 @@ impl Serial {
315315

316316
impl Write for Serial {
317317
fn write_str(&mut self, s: &str) -> fmt::Result {
318-
self.write(s.as_bytes()).map(|_| ()).map_err(|_| fmt::Error)
318+
self.write_exact(s.as_bytes()).map_err(|_| fmt::Error)
319319
}
320320
}

0 commit comments

Comments
 (0)