diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2021-05-17 09:30:58 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2021-05-17 09:30:58 -0400 |
| commit | c7c93364697615edefccf281fa69b3f3af3dc67b (patch) | |
| tree | 1a6bb3a92626ac7ecebd06cb19cdaf523f71693d | |
| parent | 80ac15f667c32b1e441cffaa3237cae2990cc152 (diff) | |
| download | rust-c7c93364697615edefccf281fa69b3f3af3dc67b.tar.gz rust-c7c93364697615edefccf281fa69b3f3af3dc67b.zip | |
Avoid zero-length write_str in fmt::write
| -rw-r--r-- | library/core/src/fmt/mod.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 5cb3c9062fe..afef790ca64 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -1104,7 +1104,9 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result { None => { // We can use default formatting parameters for all arguments. for (arg, piece) in iter::zip(args.args, args.pieces) { - formatter.buf.write_str(*piece)?; + if !piece.is_empty() { + formatter.buf.write_str(*piece)?; + } (arg.formatter)(arg.value, &mut formatter)?; idx += 1; } @@ -1113,7 +1115,9 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result { // Every spec has a corresponding argument that is preceded by // a string piece. for (arg, piece) in iter::zip(fmt, args.pieces) { - formatter.buf.write_str(*piece)?; + if !piece.is_empty() { + formatter.buf.write_str(*piece)?; + } // SAFETY: arg and args.args come from the same Arguments, // which guarantees the indexes are always within bounds. unsafe { run(&mut formatter, arg, &args.args) }?; |
