authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-06-19 21:10:20+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-19 15:20:49-07:00
logc6e2e1ae4b85fc36acc89c9a5e2673834146d628
tree23efbd861edc037dac7b05ded45b1dfb63c9c85f
parent8bd07fb1be034556874bdafb5cf895e2f941a6bc

std.fmt: fix error set of formatDuration


1 files changed, 8 insertions(+), 8 deletions(-)

lib/std/fmt.zig+8-8
......@@ -1488,7 +1488,7 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
14881488 var fbs = std.io.fixedBufferStream(&buf);
14891489 var buf_writer = fbs.writer();
14901490 if (data.negative) {
1491 try buf_writer.writeByte('-');
1491 buf_writer.writeByte('-') catch unreachable;
14921492 }
14931493
14941494 var ns_remaining = data.ns;
......@@ -1501,8 +1501,8 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
15011501 }) |unit| {
15021502 if (ns_remaining >= unit.ns) {
15031503 const units = ns_remaining / unit.ns;
1504 try formatInt(units, 10, .lower, .{}, buf_writer);
1505 try buf_writer.writeByte(unit.sep);
1504 formatInt(units, 10, .lower, .{}, buf_writer) catch unreachable;
1505 buf_writer.writeByte(unit.sep) catch unreachable;
15061506 ns_remaining -= units * unit.ns;
15071507 if (ns_remaining == 0)
15081508 return formatBuf(fbs.getWritten(), options, writer);
......@@ -1516,7 +1516,7 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
15161516 }) |unit| {
15171517 const kunits = ns_remaining * 1000 / unit.ns;
15181518 if (kunits >= 1000) {
1519 try formatInt(kunits / 1000, 10, .lower, .{}, buf_writer);
1519 formatInt(kunits / 1000, 10, .lower, .{}, buf_writer) catch unreachable;
15201520 const frac = kunits % 1000;
15211521 if (frac > 0) {
15221522 // Write up to 3 decimal places
......@@ -1526,15 +1526,15 @@ fn formatDuration(data: FormatDurationData, comptime fmt: []const u8, options: s
15261526 while (end > 1) : (end -= 1) {
15271527 if (decimal_buf[end - 1] != '0') break;
15281528 }
1529 try buf_writer.writeAll(decimal_buf[0..end]);
1529 buf_writer.writeAll(decimal_buf[0..end]) catch unreachable;
15301530 }
1531 try buf_writer.writeAll(unit.sep);
1531 buf_writer.writeAll(unit.sep) catch unreachable;
15321532 return formatBuf(fbs.getWritten(), options, writer);
15331533 }
15341534 }
15351535
1536 try formatInt(ns_remaining, 10, .lower, .{}, buf_writer);
1537 try buf_writer.writeAll("ns");
1536 formatInt(ns_remaining, 10, .lower, .{}, buf_writer) catch unreachable;
1537 buf_writer.writeAll("ns") catch unreachable;
15381538 return formatBuf(fbs.getWritten(), options, writer);
15391539}
15401540