authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-02 10:02:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-02 17:22:15-04:00
log85eb5a3069c132388191e9531802ccfd993737f1
tree3f93abadd40323c76c0a734e9861f779360d580e
parent0c2cd83814e9c4db6c51ff7c2ea2e4678a35f5e4

std.Progress: fix line upper bound calculation

closes #20161 problem introduced in e09963d8544c19812db20e520f09f6e5d9a57d64

1 files changed, 14 insertions(+), 9 deletions(-)

lib/std/Progress.zig+14-9
......@@ -1106,6 +1106,7 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) struct { []u8, usize } {
11061106fn computePrefix(
11071107 buf: []u8,
11081108 start_i: usize,
1109 nl_n: usize,
11091110 serialized: Serialized,
11101111 children: []const Children,
11111112 node_index: Node.Index,
......@@ -1118,25 +1119,29 @@ fn computePrefix(
11181119 {
11191120 return i;
11201121 }
1121 i = computePrefix(buf, i, serialized, children, parent_index);
1122 i = computePrefix(buf, i, nl_n, serialized, children, parent_index);
11221123 if (children[@intFromEnum(parent_index)].sibling == .none) {
11231124 const prefix = " ";
1124 const upper_bound_len = prefix.len + line_upper_bound_len;
1125 const upper_bound_len = prefix.len + lineUpperBoundLen(nl_n);
11251126 if (i + upper_bound_len > buf.len) return buf.len;
11261127 buf[i..][0..prefix.len].* = prefix.*;
11271128 i += prefix.len;
11281129 } else {
1129 const upper_bound_len = comptime (TreeSymbol.line.maxByteLen() + line_upper_bound_len);
1130 const upper_bound_len = TreeSymbol.line.maxByteLen() + lineUpperBoundLen(nl_n);
11301131 if (i + upper_bound_len > buf.len) return buf.len;
11311132 i = appendTreeSymbol(.line, buf, i);
11321133 }
11331134 return i;
11341135}
11351136
1136// \r\n on Windows, \n otherwise.
1137const nl_len = if (is_windows) 2 else 1;
1138const line_upper_bound_len = @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) +
1139 "[4294967296/4294967296] ".len + Node.max_name_len + nl_len + (1 + up_one_line.len) + finish_sync.len;
1137fn lineUpperBoundLen(nl_n: usize) usize {
1138 // \r\n on Windows, \n otherwise.
1139 const nl_len = if (is_windows) 2 else 1;
1140 return @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) +
1141 "[4294967296/4294967296] ".len + Node.max_name_len + nl_len +
1142 (1 + (nl_n + 1) * up_one_line.len) +
1143 finish_sync.len;
1144}
11401145
11411146fn computeNode(
11421147 buf: []u8,
......@@ -1149,9 +1154,9 @@ fn computeNode(
11491154 var i = start_i;
11501155 var nl_n = start_nl_n;
11511156
1152 i = computePrefix(buf, i, serialized, children, node_index);
1157 i = computePrefix(buf, i, nl_n, serialized, children, node_index);
11531158
1154 if (i + line_upper_bound_len > buf.len)
1159 if (i + lineUpperBoundLen(nl_n) > buf.len)
11551160 return .{ start_i, start_nl_n };
11561161
11571162 const storage = &serialized.storage[@intFromEnum(node_index)];