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 } {...@@ -1106,6 +1106,7 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) struct { []u8, usize } {
1106fn computePrefix(1106fn computePrefix(
1107 buf: []u8,1107 buf: []u8,
1108 start_i: usize,1108 start_i: usize,
1109 nl_n: usize,
1109 serialized: Serialized,1110 serialized: Serialized,
1110 children: []const Children,1111 children: []const Children,
1111 node_index: Node.Index,1112 node_index: Node.Index,
...@@ -1118,25 +1119,29 @@ fn computePrefix(...@@ -1118,25 +1119,29 @@ fn computePrefix(
1118 {1119 {
1119 return i;1120 return i;
1120 }1121 }
1121 i = computePrefix(buf, i, serialized, children, parent_index);1122 i = computePrefix(buf, i, nl_n, serialized, children, parent_index);
1122 if (children[@intFromEnum(parent_index)].sibling == .none) {1123 if (children[@intFromEnum(parent_index)].sibling == .none) {
1123 const prefix = " ";1124 const prefix = " ";
1124 const upper_bound_len = prefix.len + line_upper_bound_len;1125 const upper_bound_len = prefix.len + lineUpperBoundLen(nl_n);
1125 if (i + upper_bound_len > buf.len) return buf.len;1126 if (i + upper_bound_len > buf.len) return buf.len;
1126 buf[i..][0..prefix.len].* = prefix.*;1127 buf[i..][0..prefix.len].* = prefix.*;
1127 i += prefix.len;1128 i += prefix.len;
1128 } else {1129 } 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);
1130 if (i + upper_bound_len > buf.len) return buf.len;1131 if (i + upper_bound_len > buf.len) return buf.len;
1131 i = appendTreeSymbol(.line, buf, i);1132 i = appendTreeSymbol(.line, buf, i);
1132 }1133 }
1133 return i;1134 return i;
1134}1135}
11351136
1136// \r\n on Windows, \n otherwise.1137fn lineUpperBoundLen(nl_n: usize) usize {
1137const nl_len = if (is_windows) 2 else 1;1138 // \r\n on Windows, \n otherwise.
1138const line_upper_bound_len = @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) +1139 const nl_len = if (is_windows) 2 else 1;
1139 "[4294967296/4294967296] ".len + Node.max_name_len + nl_len + (1 + up_one_line.len) + finish_sync.len;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
1141fn computeNode(1146fn computeNode(
1142 buf: []u8,1147 buf: []u8,
...@@ -1149,9 +1154,9 @@ fn computeNode(...@@ -1149,9 +1154,9 @@ fn computeNode(
1149 var i = start_i;1154 var i = start_i;
1150 var nl_n = start_nl_n;1155 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)
1155 return .{ start_i, start_nl_n };1160 return .{ start_i, start_nl_n };
11561161
1157 const storage = &serialized.storage[@intFromEnum(node_index)];1162 const storage = &serialized.storage[@intFromEnum(node_index)];