Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the scope and closure bugs pattern
Every callback reports the last value, a counter never increments, UnboundLocalError on a variable you can see.
What went wrong: fullPath is a local std::string allocated on the stack. Returning a std::string_view references the internal buffer of fullPath, which is destroyed upon function return, leaving a dangling pointer.
The fix: Return an owned std::string instead of a non-owning std::string_view.
Remember: Never return a std::string_view (or raw pointer) referencing a local temporary variable.
The pattern behind it: scope and closure bugs.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/2b5aee42-4e8e-4e94-a9b7-1c1f86f7b05e" title="Debugging challenge: Dangling string_view to temporary std::string" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/2b5aee42-4e8e-4e94-a9b7-1c1f86f7b05e">TryBugHunt</a></p>