rust.unbounded_recursion
Stability
High
Detects recursive functions without depth limits that can cause stack overflow.
Why It Matters
Section titled “Why It Matters”Unbounded recursion:
- Stack overflow — Program crashes
- No recovery — SIGSEGV is fatal
- Hard to debug — Happens deep in call stack
Example
Section titled “Example”// ❌ Before (unbounded recursion)fn traverse(node: &Node) { process(node); for child in &node.children { traverse(child); // No depth limit! }}// ✅ After (with depth limit)fn traverse(node: &Node, depth: usize) -> Result<(), Error> { if depth > 100 { return Err(Error::MaxDepthExceeded); } process(node); for child in &node.children { traverse(child, depth + 1)?; } Ok(())}What Unfault Detects
Section titled “What Unfault Detects”- Recursive functions without base case
- Missing depth counters
- Self-referential data traversal
Auto-Fix
Section titled “Auto-Fix”Unfault adds depth parameters and checks.