From b6c38bfeff4392e5f0f6097ca2722646869c47d8 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Tue, 17 Aug 2021 23:09:28 -0400 Subject: [PATCH] Fix FmtToIoWriter::write_str to call write_all Previously, the implementation could silently fail to write some bytes. Now, the implementation should either write all the bytes or return an error. The docs for `std::fmt::Write::write_str` say, "This method can only succeed if the entire string slice was successfully written, and this method will not return until all data has been written or an error occurs." So, `FmtToIoWriter::write_str` must call `std::io::Write::write_all` instead of `std::io::Write::write` on the inner writer in order to ensure that all the bytes are written. --- src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ser.rs b/src/ser.rs index 8b01faf2..f97efa50 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -867,7 +867,7 @@ where W: io::Write, { fn write_str(&mut self, s: &str) -> fmt::Result { - if self.writer.write(s.as_bytes()).is_err() { + if self.writer.write_all(s.as_bytes()).is_err() { return Err(fmt::Error); } Ok(())