resizeNode / countLeavesNode may overflow stack on deeply nested layoutsresizeNode / countLeavesNode may overflow stack on deeply nested layoutsFile: src/window.zig:226–243, src/layout.zig:235–240
Severity: MEDIUM
Status: ✅ FIXED — both functions converted from recursive to iterative using explicit heap-allocated stacks via std.ArrayListUnmanaged. Unit test verifies countLeaves handles 500-deep nested splits without overflowing.
// window.zig:226
fn resizeNode(self: *Window, node: *const Node, lw: u32, lh: u32) Error!void {
switch (node.*) {
.leaf => |pane| try pane.resizeTerminal(lw, lh),
.split => |s| {
// recursive calls — no tail recursion, no iteration
try self.resizeNode(s.a, ...);
try self.resizeNode(s.b, ...);
},
}
}
// layout.zig:235
fn countLeavesNode(self: *const Layout, node: *const Node) usize {
switch (node.*) {
.leaf => return 1,
.split => |s| return self.countLeavesNode(s.a) + self.countLeavesNode(s.b),
}
}
Both resizeNode and countLeavesNode recurse through the layout tree. With ~1000+ deeply nested splits (e.g. creating panes via repeated splits without using the full layout), the recursion depth equals the number of splits, which can overflow the stack. Zig’s default stack is ~1 MiB; a resizeNode frame is ~64 bytes, so ~16,000 frames would overflow. In practice, creating more than ~256 panes triggers this.
Impact: Crash (stack overflow) when creating many deeply nested split panes.